Skip to main content
Every agent requires an interfaces.LLMClient. Pass it to NewAgent with WithLLMClient. Built-in clients live under pkg/llm/ and share option helpers from pkg/llm:
import "github.com/agenticenv/agent-sdk-go/pkg/llm"

Supported providers

ProviderPackageGetProvider() value
OpenAIpkg/llm/openaiopenai
Anthropicpkg/llm/anthropicanthropic
Geminipkg/llm/geminigemini
All three implement the same interface:
type LLMClient interface {
    Generate(ctx context.Context, request *LLMRequest) (*LLMResponse, error)
    GenerateStream(ctx context.Context, request *LLMRequest) (LLMStream, error)
    GetModel() string
    GetProvider() LLMProvider
    IsStreamSupported() bool
}

OpenAI

import (
    "github.com/agenticenv/agent-sdk-go/pkg/llm"
    "github.com/agenticenv/agent-sdk-go/pkg/llm/openai"
)

llmClient, err := openai.NewClient(
    llm.WithAPIKey(os.Getenv("OPENAI_API_KEY")),
    llm.WithModel("gpt-4o"),
    llm.WithBaseURL("https://api.openai.com/v1"), // optional — for proxies or Azure-compatible endpoints
)
if err != nil {
    return err
}
Common models: 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

import (
    "github.com/agenticenv/agent-sdk-go/pkg/llm"
    "github.com/agenticenv/agent-sdk-go/pkg/llm/anthropic"
)

llmClient, err := anthropic.NewClient(
    llm.WithAPIKey(os.Getenv("ANTHROPIC_API_KEY")),
    llm.WithModel("claude-sonnet-4-20250514"),
)
Anthropic supports extended thinking via WithLLMSampling. See Reasoning.

Gemini

import (
    "github.com/agenticenv/agent-sdk-go/pkg/llm"
    "github.com/agenticenv/agent-sdk-go/pkg/llm/gemini"
)

llmClient, err := gemini.NewClient(
    llm.WithAPIKey(os.Getenv("GOOGLE_API_KEY")),
    llm.WithModel("gemini-2.5-flash"),
)
llm.WithAPIKey takes precedence. If you omit it, the Gemini client falls back to the GOOGLE_API_KEY environment variable automatically.

Shared LLM options

All built-in clients accept functional options from pkg/llm:
OptionPurpose
llm.WithAPIKey(key)Provider API key
llm.WithModel(model)Model name sent to the provider
llm.WithBaseURL(url)Custom base URL (OpenAI-compatible endpoints, proxies)

Sampling and reasoning

Control temperature, max tokens, and reasoning per agent with WithLLMSampling:
temp := 0.7
a, err := agent.NewAgent(
    agent.WithLLMClient(llmClient),
    agent.WithLLMSampling(&agent.LLMSampling{
        Temperature: &temp,
        MaxTokens:   4096,
    }),
)
Field support varies by provider:
FieldOpenAIAnthropicGemini
Temperature
MaxTokens
TopP
TopK
ReasoningPartial
See Reasoning for extended thinking configuration per provider.

Bring your own LLM client

Implement interfaces.LLMClient and pass your implementation to WithLLMClient. Your implementation must handle:
  • Generate — synchronous completion; populate LLMResponse.ToolCalls when the provider returns tool calls
  • GenerateStream — streaming chunks via LLMStream.Next() and LLMStream.Current() when IsStreamSupported() returns true
  • GetModel / GetProvider — metadata that appears on AgentRunResult.Model and AgentRunResult.AgentName
Copy the patterns from pkg/llm/openai, pkg/llm/anthropic, or pkg/llm/gemini as a starting point — they show request marshaling, response parsing, tool call handling, and stream chunk iteration.

Quickstart

Run your first agent end to end

Configuration

WithLLMClient, WithLLMSampling, and other options

Reasoning

Extended thinking on Anthropic and Gemini

Token Usage

Read LLMUsage from run results