Ten short, runnable scripts that teach Agentic Context Engineering from a first playbook to a self-improving OpenAI Agents SDK agent. Recipes 01–07 need no API key and are verified in CI.
Construct, learn, evaluate — then point the same code at a real model.
from ace import ACE, SimulatedLLM, TeachingEnvironment, build_teaching_task
env = TeachingEnvironment()
task = build_teaching_task()
train, test = task.split()
ace = ACE(SimulatedLLM(env))
ace.adapt_offline(train) # build a playbook from feedback
print(ace.evaluate(test).accuracy) # measure on held-out data
print(ace.playbook.render()) # inspect what it learned
Deterministic, offline, and covered by tests/test_cookbook.py.
first_playbookThe three-line workflow — construct → adapt_offline → evaluate — and the accuracy lift over a base LLM with no context.
online_adaptationTest-time learning: predict-then-learn per sample, and proving the agent improves with windowed accuracy.
your_own_taskDefine a Task from your own Samples and scorer — ACE makes no assumptions about your domain.
label_free_feedbackLearn with no gold labels via a feedback_fn that returns execution signals — the realistic production setting.
save_and_resumePersist a playbook to JSON and warm-start a fresh engine from it — memory that survives a restart.
grow_and_refineDe-duplicate near-identical bullets and prune consistently harmful ones — deterministic, non-LLM compaction.
inspect_and_reportIntrospect bullets and stats, then render a polished, dependency-free HTML report of a run.
Install the extras and set a key:
pip install "ace-playbook[all]" && export OPENAI_API_KEY=sk-...
agent_quickstartwrap_agent in one call: playbook injection on every run, run_and_learn, and save() for durable memory.
auto_learn_from_tool_errorsCapture hooks turn a failed tool call into an automatic learning signal — no explicit feedback required. Read out.auto_signal / out.events.
streaming_and_sessionsStream and learn with arun_streamed_and_learn, and compose ACE's learned memory with an SDK session for multi-turn history.
Start with the regimes, then your data, then operations, then agents.
01 first_playbook ─► 02 online_adaptation ─► 03 your_own_task ─► 04 label_free_feedback
│ │
▼ ▼
05 save_and_resume ─► 06 grow_and_refine ─► 07 inspect_and_report │
▼
08 agent_quickstart ─► 09 auto_learn ─► 10 streaming/sessions