Catalog PyPI
Back to packageRELEASE DETAILS

0.1.4

PyPI

ace-context-engineering

Agentic Context Engineering (ACE) - Evolving contexts for self-improving language models

agentic-aiaicontext-engineeringcurationllmplaybookreflectionself-improving
Published6 Nov 2025
Direct dependencies22
Transitive dependenciesNot calculated

README

Version 0.1.4 documentation

ACE Context Engineering

PyPI version Python 3.11+ License: MIT

Self-improving AI agents through evolving playbooks. Wrap any LangChain agent with ACE to enable learning from experience without fine-tuning.

Based on research: Agentic Context Engineering (Stanford/SambaNova, 2025)


What is ACE?

ACE enables AI agents to learn and improve by accumulating strategies in a "playbook" - a knowledge base that grows smarter with each interaction.

Key Benefits

  • +17% task performance improvement
  • 82% faster adaptation to new domains
  • 75% lower computational cost vs fine-tuning
  • Zero model changes - works with any LLM

Installation

Using pip

# Default (FAISS vector store)
pip install ace-context-engineering

# With ChromaDB support
pip install ace-context-engineering[chromadb]

# With Qdrant support
pip install ace-context-engineering[qdrant]
# or: pip install qdrant-client
# Default (FAISS vector store)
uv add ace-context-engineering

# With ChromaDB support
uv add ace-context-engineering[chromadb]

# With Qdrant support
uv add ace-context-engineering[qdrant]
# or: uv add qdrant-client

Environment Setup:

# Copy example environment file
cp .env.example .env

# Add your API key
echo "OPENAI_API_KEY=your-key-here" >> .env

Quick Start

3-Step Integration

from ace import ACEConfig, ACEAgent, PlaybookManager
from langchain.chat_models import init_chat_model

# 1. Configure ACE
config = ACEConfig(
    playbook_name="my_app",
    vector_store="faiss",
    top_k=10
)

playbook = PlaybookManager(
    playbook_dir=config.get_storage_path(),
    vector_store=config.vector_store,
    embedding_model=config.embedding_model
)

# 2. Wrap your agent
base_agent = init_chat_model("openai:gpt-4o-mini")
agent = ACEAgent(
    base_agent,
    playbook,
    config,
    auto_inject=True  # Automatic context injection
)

# 3. Use normally - ACE handles context automatically!
response = agent.invoke([
    {"role": "user", "content": "Process payment for order #12345"}
])

# 4. Provide feedback for learning (optional but recommended)
chat_data = agent.get_last_interaction()  # Get interaction data
result = agent.submit_feedback(
    user_feedback="Payment processed successfully",
    rating=5,
    chat_data=chat_data  # Explicit for production/parallel users
)

Add Knowledge to Playbook

# Add strategies manually
playbook.add_bullet(
    content="Always validate order exists before processing payment",
    section="Payment Processing"
)

playbook.add_bullet(
    content="Log all failed transactions with error codes",
    section="Error Handling"
)

Learning from Feedback

Simple API (Recommended):

# After agent response, provide feedback
chat_data = agent.get_last_interaction()  # Get current interaction data

result = agent.submit_feedback(
    user_feedback="Payment processed successfully",
    rating=5,  # 1-5 scale
    feedback_type="positive",
    chat_data=chat_data  # Explicit for thread-safety in production
)

# ACE automatically:
# 1. Reflector analyzes feedback → extracts insights
# 2. Curator creates/updates playbook bullets
# 3. Playbook improves for future interactions!

For Async/Parallel Users:

# Use async API for better performance
chat_data = {
    "question": user_question,
    "model_response": response.content,
    "used_bullets": agent.get_used_bullets()
}

result = await agent.asubmit_feedback(
    user_feedback="Great response!",
    rating=5,
    chat_data=chat_data  # Required for thread-safety
)

Architecture

┌─────────────────┐
│   Your Agent    │ ← Any LangChain agent
│   (Generator)   │
└─────────┬───────┘
          │
          ▼
┌─────────────────┐
│   ACEAgent      │ ← Automatic context injection
│   Wrapper       │
└─────────┬───────┘
          │
          ▼
┌─────────────────┐
│   Playbook      │ ← Semantic knowledge retrieval
│   Manager       │
└─────────────────┘
          ▲
          │
┌─────────────────┐
│   Reflector     │ ← Analyzes feedback
│   + Curator     │ ← Updates playbook
└─────────────────┘

Components

ComponentPurposeUses LLM?Key Features
ACEAgentWraps your agent, injects contextNoThread-safe with chat_data param, async support
PlaybookManagerStores & retrieves knowledgeNoUses embeddings for semantic search
ReflectorAnalyzes feedback, extracts insightsYesMulti-iteration refinement, auto-critique
CuratorUpdates playbook deterministicallyNoUses embeddings for similarity matching (no LLM)

Configuration

from ace import ACEConfig

config = ACEConfig(
    playbook_name="my_app",           # Unique name for your app
    vector_store="faiss",             # "faiss", "chromadb", "qdrant", or "qdrant-cloud"
    storage_path="./.ace/playbooks",  # Optional: custom path
    chat_model="openai:gpt-4o-mini",  # For Reflector (feedback analysis)
    embedding_model="openai:text-embedding-3-small",  # For semantic search
    temperature=0.3,                  # LLM temperature
    top_k=10,                         # Number of bullets to retrieve
    deduplication_threshold=0.9,      # Similarity threshold for deduplication
    # Qdrant-specific (only needed for qdrant/qdrant-cloud)
    qdrant_url="http://localhost:6333",  # Qdrant server URL
    qdrant_api_key=None               # Required for qdrant-cloud, optional for qdrant
)

# Note: Curator does NOT use LLM - it's deterministic
# Curator uses embeddings via PlaybookManager for similarity matching

Storage Location

FAISS/ChromaDB (Local Storage): By default, ACE stores playbooks in ./.ace/playbooks/{playbook_name}/ (like .venv):

your-project/
 .venv/              ← Virtual environment
 .ace/               ← ACE storage
    playbooks/
        my_app/
            faiss_index.bin  (or chromadb/)
            metadata.json
            playbook.md
 your_code.py

Qdrant (External Vector Storage): With Qdrant, playbook metadata stays local, but vectors are stored externally:

your-project/
 .ace/
    playbooks/
        my_app/
            metadata.json      ← Local (bullet content, counters)
            playbook.md        ← Local
            # NO vector files   ← Vectors stored in Qdrant server

Qdrant Server (Docker/Cloud):
    Collection: my_app
        └── Vectors (embeddings) ← External

Qdrant Setup:

  • Local (Docker): docker run -p 6333:6333 -p 6334:6334 qdrant/qdrant
  • Cloud: Get URL and API key from Qdrant Cloud

Examples

Check the examples/ directory for complete examples:


Testing

# Run all tests
uv run pytest tests/ -v

# Run simple learning test (5 questions with feedback)
uv run pytest tests/test_simple_learning.py -v -s

# Or run directly (requires OPENAI_API_KEY in .env)
uv run python tests/test_simple_learning.py

# Run specific test suite
uv run pytest tests/test_e2e_learning.py -v -s

# Run with coverage
uv run pytest tests/ --cov=ace --cov-report=html

All tests passing ✓


Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Documentation


License

This project is licensed under the MIT License - see the LICENSE file for details.


Acknowledgments


Contact


Star this repo if you find it useful!

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 34

Native requirements
22 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
faiss-cpu
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
faiss-cpu>=1.7.4runtime
langchain-anthropic
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
langchain-anthropic>=0.1.0runtime
langchain-core
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
langchain-core>=0.1.0runtime
langchain-openai
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
langchain-openai>=0.1.0runtime
langchain
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
langchain>=0.1.0runtime
notebook
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
notebook>=7.4.7runtime
numpy
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
numpy>=1.21.0runtime
pydantic
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
pydantic>=2.0.0runtime
python-dotenv
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
python-dotenv>=1.0.0runtime
qdrant-client
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
qdrant-client>=1.15.1runtime
black
Environment
{
  "extras": "",
  "marker": "extra == \"all\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
black>=23.0.0; extra == "all"runtime
chromadb
Environment
{
  "extras": "",
  "marker": "extra == \"all\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
chromadb>=0.4.0; extra == "all"runtime
flake8
Environment
{
  "extras": "",
  "marker": "extra == \"all\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
flake8>=6.0.0; extra == "all"runtime
isort
Environment
{
  "extras": "",
  "marker": "extra == \"all\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
isort>=5.12.0; extra == "all"runtime
mkdocs-material
Environment
{
  "extras": "",
  "marker": "extra == \"all\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
mkdocs-material>=9.0.0; extra == "all"runtime
mkdocs
Environment
{
  "extras": "",
  "marker": "extra == \"all\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
mkdocs>=1.5.0; extra == "all"runtime
mkdocstrings
Environment
{
  "extras": "",
  "marker": "extra == \"all\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
mkdocstrings>=0.22.0; extra == "all"runtime
mypy
Environment
{
  "extras": "",
  "marker": "extra == \"all\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
mypy>=1.0.0; extra == "all"runtime
pre-commit
Environment
{
  "extras": "",
  "marker": "extra == \"all\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
pre-commit>=3.0.0; extra == "all"runtime
pytest-asyncio
Environment
{
  "extras": "",
  "marker": "extra == \"all\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
pytest-asyncio>=0.21.0; extra == "all"runtime
pytest-cov
Environment
{
  "extras": "",
  "marker": "extra == \"all\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
pytest-cov>=4.0.0; extra == "all"runtime
pytest
Environment
{
  "extras": "",
  "marker": "extra == \"all\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
pytest>=7.0.0; extra == "all"runtime
chromadb
Environment
{
  "extras": "",
  "marker": "extra == \"chromadb\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
chromadb>=0.4.0; extra == "chromadb"runtime
black
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
black>=23.0.0; extra == "dev"runtime
flake8
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
flake8>=6.0.0; extra == "dev"runtime
isort
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
isort>=5.12.0; extra == "dev"runtime
mypy
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
mypy>=1.0.0; extra == "dev"runtime
pre-commit
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
pre-commit>=3.0.0; extra == "dev"runtime
pytest-asyncio
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
pytest-asyncio>=0.21.0; extra == "dev"runtime
pytest-cov
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
pytest-cov>=4.0.0; extra == "dev"runtime
pytest
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
pytest>=7.0.0; extra == "dev"runtime
mkdocs-material
Environment
{
  "extras": "",
  "marker": "extra == \"docs\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
mkdocs-material>=9.0.0; extra == "docs"runtime
mkdocs
Environment
{
  "extras": "",
  "marker": "extra == \"docs\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
mkdocs>=1.5.0; extra == "docs"runtime
mkdocstrings
Environment
{
  "extras": "",
  "marker": "extra == \"docs\"",
  "requires_python": ">=3.11",
  "evaluation": "NOT_EVALUATED"
}
mkdocstrings>=0.22.0; extra == "docs"runtime

Distribution files

2 collected
ace_context_engineering-0.1.4-py3-none-any.whl

bdist_wheel · 52.29 KB · Python py3

Source file
ace_context_engineering-0.1.4.tar.gz

sdist · 67.7 KB · Python source

Source file

Repository

PENDING
suyodhanj6/ace-context-engineering

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 18:06 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:d25fb38bc5dd6d4af5b9c0c648e8b7405328aec7978afbf661e027bb353f0f52

Other collected versions

View all collected versions →