Model resolution
Agents can specify their model in two ways:- Model name (auto-resolved)
- Pre-built client
Pass a model name string. AFK resolves it to an LLM client using the default provider.The resolution order:
- Check
agent.model_resolver(custom function) - Check registered adapters for matching provider prefix
- Default to OpenAI adapter
How the runner uses the LLM
On each step of the agent loop:Request construction
The runner builds anLLMRequest from multiple sources:
| Source | Contributes | Priority |
|---|---|---|
Agent.instructions | System message | Highest |
| Thread history | Previous messages | — |
user_message | User message | — |
Agent.tools | Tool schemas | — |
Agent.subagents | Transfer tool schemas | — |
RunnerConfig | Temperature, max_tokens | Lowest |
Streaming integration
When usingrun_stream(), the runner passes through streaming events from the LLM:
text_delta events come from two paths:
- Provider streaming when the adapter supports stream deltas.
- Runner fallback chunking of final text for non-streaming providers.
Error handling
LLM errors are classified and handled automatically:| Error | Classification | Runner behavior |
|---|---|---|
| Rate limit (429) | Retryable | Retry with backoff |
| Server error (500, 502, 503) | Retryable | Retry with backoff |
| Auth error (401, 403) | Terminal | Fail the run |
| Invalid request (400) | Terminal | Fail the run |
| Timeout | Retryable | Retry (if attempts remain) |
| Circuit breaker open | Terminal | Try fallback model or fail |
| All retries exhausted | Terminal | Try fallback model or fail |
Model selection guide
| Task | Recommended model | Why |
|---|---|---|
| Simple Q&A, classification | gpt-5.2-nano | Fast, cheap, good enough |
| General purpose with tools | gpt-5.2-mini | Best balance of cost and capability |
| Complex reasoning, coding | gpt-5.2 or claude-opus-4-5 | Better at multi-step reasoning |
| Cost-sensitive batch | gpt-5.2-nano | Lowest cost per token |
| Maximum quality | gpt-5.2 + temperature=0.0 | Deterministic, highest quality |