Skip to main content
This page explains how agents connect to the LLM layer — from model resolution to request construction, streaming, and error handling.

Model resolution

Agents can specify their model in two ways:
Pass a model name string. AFK resolves it to an LLM client using the default provider.
The resolution order:
  1. Check agent.model_resolver (custom function)
  2. Check registered adapters for matching provider prefix
  3. Default to OpenAI adapter

How the runner uses the LLM

On each step of the agent loop:

Request construction

The runner builds an LLMRequest from multiple sources:

Streaming integration

When using run_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.
Tool and step events are generated by the runner.

Error handling

LLM errors are classified and handled automatically:

Model selection guide

Treat these as example starting points. Confirm current model names, prices, and rate limits with the provider you use.

Next steps

Core Runner

The step loop and execution engine.

Streaming

Real-time event streaming API.