interfaces.LLMClient. Pass it to NewAgent with WithLLMClient.
Built-in clients live under pkg/llm/ and share option helpers from pkg/llm:
Supported providers
They all implement the same interface:
OpenAI
gpt-4o, gpt-4o-mini. The model name is sent as-is to the provider — an invalid name will return an API error at run time, not at NewAgent.
Anthropic
WithLLMSampling. See Reasoning.
Prompt caching
Anthropic supports prompt-cache breakpoints (cache_control) that let the provider reuse the KV-cache for the stable part of a request — system prompt, tool definitions, and everything up to the second-to-last message — instead of reprocessing it every call. Enable it with llm.WithPromptCaching:
WithPromptCaching is Anthropic-only — OpenAI, Gemini, and DeepSeek ignore it (OpenAI caches automatically server-side with no client-side option needed; Gemini/DeepSeek have no equivalent in this SDK today).
See Token Usage for how to measure CachedPromptTokens and confirm caching is actually being hit.
Gemini
llm.WithAPIKey takes precedence. If you omit it, the Gemini client falls back to the GOOGLE_API_KEY environment variable automatically.DeepSeek
DeepSeek exposes an OpenAI-compatible API. The base URL defaults tohttps://api.deepseek.com, so WithBaseURL is optional.
deepseek-chat and deepseek-reasoner. Reasoning is not configured via the Reasoning field — deepseek-reasoner reasons automatically, and its trace surfaces via the streaming LLMStreamChunk.ThinkingDelta and, for non-streaming responses, LLMResponse.Metadata["reasoning_content"].
DeepSeek supports only plain JSON mode, not schema-constrained output. A response format with
Type: ResponseFormatJSON maps to DeepSeek’s json_object; any Schema is ignored (not enforced by the API), so prompt the model for the shape you want, and include the word “json” in the conversation.Ollama
Ollama runs open models locally and exposes an OpenAI-compatible API, so no API key is needed. The base URL defaults tohttp://localhost:11434/v1; pass WithBaseURL to reach a remote host.
ollama pull, e.g. llama3.2, qwen2.5, mistral. Start the daemon with ollama serve. Reasoning models such as deepseek-r1 and qwen3 surface their trace via the streaming LLMStreamChunk.ThinkingDelta and, for non-streaming responses, LLMResponse.Metadata["reasoning_content"].
Ollama Cloud
Ollama Cloud hosts larger models behind an API key, for machines that can’t run them locally. Supplying an API key — viallm.WithAPIKey or the OLLAMA_API_KEY environment variable — automatically switches the default base URL to Ollama Cloud’s endpoint (https://ollama.com/v1); no other code change is needed. llm.WithBaseURL still overrides either default, e.g. for a self-hosted daemon behind an auth proxy.
Not every Ollama model supports tool-calling or JSON mode, so tool use and response formats behave differently depending on which model you pull or select on Cloud. As with DeepSeek, a response format with
Type: ResponseFormatJSON maps to json_object; any Schema is ignored, so prompt the model for the shape you want.Shared LLM options
All built-in clients accept functional options frompkg/llm:
Sampling and reasoning
Control temperature, max tokens, and reasoning per agent withWithLLMSampling:
See Reasoning for extended thinking configuration per provider.
Bring your own LLM client
Implementinterfaces.LLMClient and pass your implementation to WithLLMClient.
Your implementation must handle:
Generate— synchronous completion; populateLLMResponse.ToolCallswhen the provider returns tool callsGenerateStream— streaming chunks viaLLMStream.Next()andLLMStream.Current()whenIsStreamSupported()returnstrueGetModel/GetProvider— metadata that appears onAgentRunResult.ModelandAgentRunResult.AgentName
Related
Quickstart
Run your first agent end to end
Configuration
WithLLMClient, WithLLMSampling, and other options