LlmResponse is the inbound boundary of an LLM communication layer. It converts provider-specific results into a stable structure that an agent can process without scattering translation logic through Agent. section 4.5.1 section 4.5.3
A response carries three kinds of information:
- content stores ContentItem objects, including assistant Messages, ToolCalls, or both in one response. section 4.5.3 section 4.5.4
- error_message records network failures, rate limits, and invalid requests so the agent can retry or inform the user instead of crashing. section 4.5.3 section 4.5.4
- usage_metadata stores input and output token counts for cost management and debugging; detailed monitoring is deferred. section 4.5.3
Agent response flow
An LlmRequest containing a user Message reaches LlmClient.generate(). The client calls the provider, parses returned text into a Message or tool requests into ToolCalls, and returns an LlmResponse that the agent iterates to extract the answer or execute tools. section 4.5.4 section 4.5.5
Listing 4.10 LlmResponse class
class LlmResponse(BaseModel):
"""Response object from LLM calls."""
content: List[ContentItem] = Field(default_factory=list)
error_message: Optional[str] = None
usage_metadata: Dict[str, Any] = Field(default_factory=dict)
Inspect the minimal Pydantic model: content defaults to an empty list, while errors and usage metadata remain optional or empty. section 4.5.3
