Import map
| Task | Public import |
|---|---|
| Define an agent | from afk.agents import Agent |
| Configure fail-safe limits | from afk.agents import FailSafeConfig |
| Configure policy rules | from afk.agents import PolicyEngine, PolicyRule |
| Implement dynamic policy hooks | from afk.agents import PolicyRole |
| Run an agent | from afk.core import Runner |
| Configure the runner | from afk.core import RunnerConfig |
| Consume streaming events | from afk.core import AgentStreamEvent, AgentStreamHandle |
| Define a tool | from afk.tools import tool |
| Access tool context | from afk.tools import ToolContext |
| Build an LLM client | from afk.llms import LLMBuilder |
| Run eval suites | from afk.evals import run_suite |
| Define eval cases | from afk.evals import EvalCase, EvalBudget |
| Create memory stores | from afk.memory import InMemoryMemoryStore, SQLiteMemoryStore |
| Create task queues | from afk.queues import InMemoryTaskQueue, RedisTaskQueue, TaskWorker |
| Expose MCP tools | from afk.mcp import MCPServer |
| Use A2A messaging | from afk.messaging import InternalA2AProtocol |
src.afk.* imports in user-facing docs.
Agent
model is required. Most examples should also set name and instructions for clear traces and predictable behavior.
Runner
| Method | Use when | Returns |
|---|---|---|
runner.run_sync(agent, user_message=..., thread_id=...) | Scripts, CLIs, tests without an existing event loop | AgentResult |
await runner.run(agent, user_message=..., thread_id=...) | Async services, workers, APIs | AgentResult |
await runner.run_stream(agent, user_message=..., thread_id=...) | Chat UIs and progress streams | AgentStreamHandle |
await runner.resume(agent, run_id=..., thread_id=..., context=...) | Continue from persisted state | AgentResult |
await runner.compact_thread(thread_id=...) | Apply memory retention/compaction | MemoryCompactionResult |
run_sync() is a convenience wrapper for synchronous code. Use await runner.run(...) inside async applications.
RunnerConfig
FailSafeConfig
max_total_cost_usd for production agents. The default is intentionally unset because acceptable budgets vary by application.
Tool decorator
(args), (args, ctx), or (ctx, args).
AgentResult
| Field | Meaning |
|---|---|
final_text | Final assistant text |
state | Terminal run state |
requested_model | Model requested by the caller or agent |
normalized_model | Effective normalized model when available |
provider_adapter | Provider/adapter used when available |
tool_executions | Ordered tool execution records |
subagent_executions | Ordered subagent execution records |
usage_aggregate | Aggregated input/output/total tokens |
total_cost_usd | Estimated total cost when available |
state_snapshot | Terminal runtime snapshot payload |
API stability
- Public docs and examples should use imports from
afk.agents,afk.core,afk.tools,afk.llms,afk.memory,afk.queues,afk.mcp,afk.messaging,afk.observability, andafk.evals. - Internal modules under package subdirectories may change faster than public exports.
- When changing public exports, update this page, Public API Rules, examples, and generated agent-facing docs.