Latency
Use the smallest model that can reliably handle the task, and reserve larger models for tasks that need deeper reasoning.- keep system prompts short and specific;
- make I/O-bound tools async;
- avoid tools for information already present in context;
- stream user-facing runs with
runner.run_stream(...); - set tight
max_steps,max_llm_calls, andmax_wall_time_slimits.
Tool execution
Tools are often the slowest part of a run. Keep them typed, narrow, and bounded.- validate inputs with Pydantic models;
- enforce timeouts in external clients;
- return compact JSON-safe payloads;
- truncate or summarize large external responses before returning them;
- use
RunnerConfig(tool_output_max_chars=...)as a final bound.
Throughput
Use async runner APIs for services and workers.Cost
Set cost and loop limits on every production agent.Memory
Long threads increase prompt size and storage. Use explicit thread ids and compact retained state when threads grow.
Configure backends with environment variables or pass a public
MemoryStore implementation to Runner(memory_store=...).
Measurement
Measure fromAgentResult first:
Checklist
- Use async runner APIs in servers and workers.
- Stream user-facing runs.
- Keep prompts and tool outputs compact.
- Set fail-safe limits and cost budgets.
- Compact long-running threads.
- Move durable background work into queues.
- Monitor token usage, tool count, state, and cost per run.