Skip to main content

Class: Llm

Methods

generate()

Generate text from an LLM. Parameters: Returns: LlmResponse Raises: LlmError on generation failure Example:

generate_object()

Generate structured output conforming to a JSON Schema. Parameters: Returns: LlmResponse with .object populated Raises: LlmError on generation failure Example:

Model Resolution

Resolution order (first match wins):
  1. Fully qualified per-call - model="anthropic:claude-sonnet-4-6" used directly
  2. Bare per-call + decorator default - model="claude-sonnet-4-6" + @agent(llm={"provider": "anthropic"}) resolved to full identifier
  3. Decorator default only - @agent(llm={"provider": "anthropic", "model": "claude-sonnet-4-6"}) used when no model specified
  4. Error - No model specified and no decorator default

LlmResponse

Error Handling

Provider Options

Pass provider-specific configuration:
Options vary by provider. Common patterns: Anthropic provider:
  • thinking - Enable extended reasoning with {"type": "enabled", "budgetTokens": <int>}
Claude Code provider:
  • systemPrompt - Either {"type": "preset", "preset": "..."} or {"type": "custom", "content": "..."}
  • effort - "low", "medium", "high"
  • fallbackModel - Model to use if primary fails
  • repo - Repository to clone and work in

Message Format

Valid roles: system, user, assistant

Limitations

  • No streaming responses - Full response returned at once; streaming is not yet supported
  • 5MB implicit limit - Via platform constraints on response size

Why Host-Managed?

Agents run as native Python processes. You can pip install additional packages into the agent environment. Host-provided LLM calls are still preferred for credential management, rate limiting, provider routing, and audit logging.

See Also

How to Call LLMs

Task-oriented guide

AgentContext

Parent context object