AI agents that get smarter with every task ๐ง
Agentic Context Engine learns from your agent's successes and failures. Just plug in and watch your agents improve.
Star โญ๏ธ this repo if you find it useful!
- Direct your favorite coding agent (Cursor, Claude Code, Codex, etc) to Quick Start Guide
- Prompt away!
pip install ace-frameworkexport OPENAI_API_KEY="your-api-key"from ace import ACELiteLLM
agent = ACELiteLLM(model="gpt-4o-mini")
answer = agent.ask("What does Kayba's ACE framework do?")
print(answer) # "ACE allows AI agents to remember and learn from experience!"๐ Done! Your agent learns automatically from each interaction.
ACE provides three ready-to-use integrations:
Perfect for Q&A, classification, reasoning:
from ace import ACELiteLLM
# Create self-improving agent
agent = ACELiteLLM(model="gpt-4o-mini")
# Ask related questions - agent learns patterns
answer1 = agent.ask("If all cats are animals, is Felix (a cat) an animal?")
answer2 = agent.ask("If all birds fly, can penguins (birds) fly?") # Learns to check assumptions!
answer3 = agent.ask("If all metals conduct electricity, does copper conduct electricity?")
# View learned strategies
print(f"โ
Learned {len(agent.playbook.bullets())} reasoning strategies")
# Save for reuse
agent.save_playbook("my_agent.json")
# Load and continue
agent2 = ACELiteLLM.from_playbook("my_agent.json", model="gpt-4o-mini")Self-improving browser agents with browser-use:
pip install ace-framework[browser-use]from ace import ACEAgent
from browser_use import ChatBrowserUse
# Two LLMs: ChatBrowserUse for browser, gpt-4o-mini for ACE learning
agent = ACEAgent(
llm=ChatBrowserUse(), # Browser execution
ace_model="gpt-4o-mini" # ACE learning
)
await agent.run(task="Find top Hacker News post")
agent.save_playbook("hn_expert.json")
# Reuse learned knowledge
agent = ACEAgent(llm=ChatBrowserUse(), playbook_path="hn_expert.json")
await agent.run(task="New task") # Starts smart!Features: Drop-in replacement for browser_use.Agent, automatic learning, reusable playbooks
โ Browser Use Guide
Wrap any LangChain chain/agent with learning:
from ace import ACELangChain
ace_chain = ACELangChain(runnable=your_langchain_chain)
result = ace_chain.invoke({"question": "Your task"}) # Learns automaticallyBest for: Multi-step workflows, tool-using agents
โ Integration Guide | โ Examples
AI agents make the same mistakes repeatedly.
ACE enables agents to learn from execution feedback: what works, what doesn't, and continuously improve.
No training data, no fine-tuning, just automatic improvement.
- ๐ 20-35% Better Performance: Proven improvements on complex tasks
- ๐ง Self-Improving: Agents get smarter with each task
- ๐ No Context Collapse: Preserves valuable knowledge over time
- ๐ 100+ LLM Providers: Works with OpenAI, Anthropic, Google, and more
- ๐ Production Observability: Built-in Opik integration for enterprise monitoring
A challenge where LLMs often hallucinate that a seahorse emoji exists (it doesn't).
In this example:
- Round 1: The agent incorrectly outputs ๐ด (horse emoji)
- Self-Reflection: ACE reflects without any external feedback
- Round 2: With learned strategies from ACE, the agent successfully realizes there is no seahorse emoji
Try it yourself:
uv run python examples/kayba_ace_test.pyOnline Shopping Demo: ACE vs baseline agent shopping for 5 grocery items.
ACE Performance:
- 29.8% fewer steps (57.2 vs 81.5)
- 49.0% token reduction (595k vs 1,166k)
- 42.6% cost reduction (including ACE overhead)
โ Try it yourself & see all demos
Based on the ACE research framework from Stanford & SambaNova.
ACE uses three specialized roles that work together:
- ๐ฏ Generator - Creates strategies using learned patterns from the playbook
- ๐ Reflector - Analyzes what worked and what didn't after execution
- ๐ Curator - Updates the playbook with new strategies based on reflection
Important: The three ACE roles are different specialized prompts using the same language model, not separate models.
ACE teaches your agent and internalises:
- โ Successes โ Extract patterns that work
- โ Failures โ Learn what to avoid
- ๐ง Tool usage โ Discover which tools work best for which tasks
- ๐ฏ Edge cases โ Remember rare scenarios and how to handle them
The magic happens in the Playbookโa living document of strategies that evolves with experience.
Key innovation: All learning happens in context through incremental updatesโno fine-tuning, no training data, and complete transparency into what your agent learned.
---
config:
look: neo
theme: neutral
---
flowchart LR
Playbook[("`**๐ Playbook**<br>(Evolving Context)<br><br>โขStrategy Bullets<br> โ Helpful strategies <br>โ Harmful patterns <br>โ Neutral observations`")]
Start(["**๐Query** <br>User prompt or question"]) --> Generator["**โ๏ธGenerator** <br>Executes task using playbook"]
Generator --> Reflector
Playbook -. Provides Context .-> Generator
Environment["**๐ Task Environment**<br>Evaluates answer<br>Provides feedback"] -- Feedback+ <br>Optional Ground Truth --> Reflector
Reflector["**๐ Reflector**<br>Analyzes and provides feedback what was helpful/harmful"]
Reflector --> Curator["**๐ Curator**<br>Produces improvement deltas"]
Curator --> DeltaOps["**๐Merger** <br>Updates the playbook with deltas"]
DeltaOps -- Incremental<br>Updates --> Playbook
Generator <--> Environment
# Basic
pip install ace-framework
# With extras
pip install ace-framework[browser-use] # Browser automation
pip install ace-framework[langchain] # LangChain
pip install ace-framework[observability] # Opik monitoring
pip install ace-framework[all] # All featuresACE works with any LLM provider through LiteLLM:
# OpenAI
client = LiteLLMClient(model="gpt-4o")
# With fallbacks for reliability
client = LiteLLMClient(
model="gpt-4",
fallbacks=["claude-3-haiku", "gpt-3.5-turbo"]
)ACE includes built-in Opik integration for tracing and cost tracking:
pip install ace-framework[observability]
export OPIK_API_KEY="your-api-key"Automatically tracks: LLM calls, costs, playbook evolution. View at comet.com/opik
- Quick Start Guide - Get running in 5 minutes
- API Reference - Complete API documentation
- Examples - Ready-to-run code examples
- Browser Automation - Self-improving browser agents
- LangChain Integration - Wrap chains/agents with learning
- Custom Integration - Pattern for any agent
- Integration Guide - Add ACE to existing agents
- ACE Framework Guide - Deep dive into Agentic Context Engineering
- Prompt Engineering - Advanced prompt techniques
- Benchmarks - Evaluate ACE performance with scientific rigor across multiple datasets
- Changelog - See recent changes
We love contributions! Check out our Contributing Guide to get started.
Based on the ACE paper and inspired by Dynamic Cheatsheet.
If you use ACE in your research, please cite:
@article{zhang2024ace,title={Agentic Context Engineering},author={Zhang et al.},journal={arXiv:2510.04618},year={2024}}โญ Star this repo if you find it useful!
Built with โค๏ธ by Kayba and the open-source community.


