Documentation
¶
Index ¶
- Variables
- func CalculateCost(pricing *ModelPricing, usage *agentcore.Usage) *agentcore.Cost
- func TransformMessages(messages []agentcore.Message, targetProvider string) []agentcore.Message
- type BaseModel
- type GenerationConfig
- type LiteLLMAdapter
- func NewAnthropicModel(model, apiKey string, baseURL ...string) (*LiteLLMAdapter, error)
- func NewGeminiModel(model, apiKey string, baseURL ...string) (*LiteLLMAdapter, error)
- func NewLiteLLMAdapter(model string, client *litellm.Client) *LiteLLMAdapter
- func NewOpenAIModel(model, apiKey string, baseURL ...string) (*LiteLLMAdapter, error)
- func (l *LiteLLMAdapter) Generate(ctx context.Context, messages []agentcore.Message, tools []agentcore.ToolSpec, ...) (*agentcore.LLMResponse, error)
- func (l *LiteLLMAdapter) GenerateStream(ctx context.Context, messages []agentcore.Message, tools []agentcore.ToolSpec, ...) (<-chan agentcore.StreamEvent, error)
- func (l *LiteLLMAdapter) ProviderName() string
- type ModelCapability
- type ModelInfo
- type ModelPricing
Constants ¶
This section is empty.
Variables ¶
var DefaultGenerationConfig = &GenerationConfig{ Temperature: 0.7, TopP: 0.9, TopK: 0, MaxTokens: 65536, StopSequences: []string{}, PresencePenalty: 0.0, FrequencyPenalty: 0.0, Seed: nil, }
Functions ¶
func CalculateCost ¶ added in v1.5.1
func CalculateCost(pricing *ModelPricing, usage *agentcore.Usage) *agentcore.Cost
CalculateCost computes the monetary cost from pricing rates and token usage. Returns nil if pricing or usage is nil.
func TransformMessages ¶ added in v1.5.1
TransformMessages normalizes a message sequence for a target provider. Use this when switching models mid-conversation to avoid provider rejections.
Two-pass algorithm:
- Normalize tool call IDs (truncate >64 chars, sanitize to [a-zA-Z0-9_-]), handle thinking blocks based on target provider.
- Apply ID mapping to tool results, insert synthetic results for orphaned tool calls.
Types ¶
type BaseModel ¶
type BaseModel struct {
// contains filtered or unexported fields
}
BaseModel provides common model metadata and capability checks.
func NewBaseModel ¶
func NewBaseModel(info ModelInfo, config *GenerationConfig) *BaseModel
func (*BaseModel) GetConfig ¶
func (m *BaseModel) GetConfig() *GenerationConfig
func (*BaseModel) SupportsCapability ¶
func (m *BaseModel) SupportsCapability(capability ModelCapability) bool
func (*BaseModel) SupportsStreaming ¶
func (*BaseModel) SupportsTools ¶
type GenerationConfig ¶
type GenerationConfig struct {
Temperature float64 `json:"temperature"`
TopP float64 `json:"top_p"`
TopK int `json:"top_k"`
MaxTokens int `json:"max_tokens"`
StopSequences []string `json:"stop_sequences"`
PresencePenalty float64 `json:"presence_penalty"`
FrequencyPenalty float64 `json:"frequency_penalty"`
Seed *int64 `json:"seed"`
}
GenerationConfig defines sampling and length control parameters.
type LiteLLMAdapter ¶
type LiteLLMAdapter struct {
*BaseModel
// contains filtered or unexported fields
}
LiteLLMAdapter adapts litellm to the agentcore.ChatModel interface.
func NewAnthropicModel ¶
func NewAnthropicModel(model, apiKey string, baseURL ...string) (*LiteLLMAdapter, error)
NewAnthropicModel creates an Anthropic adapter.
func NewGeminiModel ¶
func NewGeminiModel(model, apiKey string, baseURL ...string) (*LiteLLMAdapter, error)
NewGeminiModel creates a Gemini adapter.
func NewLiteLLMAdapter ¶
func NewLiteLLMAdapter(model string, client *litellm.Client) *LiteLLMAdapter
NewLiteLLMAdapter creates an adapter from a litellm Client.
func NewOpenAIModel ¶
func NewOpenAIModel(model, apiKey string, baseURL ...string) (*LiteLLMAdapter, error)
NewOpenAIModel creates an OpenAI adapter.
func (*LiteLLMAdapter) Generate ¶
func (l *LiteLLMAdapter) Generate(ctx context.Context, messages []agentcore.Message, tools []agentcore.ToolSpec, opts ...agentcore.CallOption) (*agentcore.LLMResponse, error)
Generate produces a synchronous response.
func (*LiteLLMAdapter) GenerateStream ¶
func (l *LiteLLMAdapter) GenerateStream(ctx context.Context, messages []agentcore.Message, tools []agentcore.ToolSpec, opts ...agentcore.CallOption) (<-chan agentcore.StreamEvent, error)
GenerateStream produces a streaming response with fine-grained events. Delegates lifecycle detection to litellm's CollectStreamWithCallbacks.
func (*LiteLLMAdapter) ProviderName ¶
func (l *LiteLLMAdapter) ProviderName() string
ProviderName returns the provider name (e.g. "openai", "anthropic"). Implements agentcore.ProviderNamer for per-provider API key resolution.
type ModelCapability ¶
type ModelCapability string
ModelCapability defines capability identifiers.
const ( CapabilityChat ModelCapability = "chat" CapabilityCompletion ModelCapability = "completion" CapabilityToolCalling ModelCapability = "tool_calling" CapabilityStreaming ModelCapability = "streaming" CapabilityMultimodal ModelCapability = "multimodal" CapabilityFunctionCall ModelCapability = "function_call" )
type ModelInfo ¶
type ModelInfo struct {
Name string `json:"name"`
Provider string `json:"provider"`
Version string `json:"version"`
MaxTokens int `json:"max_tokens"`
ContextSize int `json:"context_size"`
Capabilities []string `json:"capabilities"`
Pricing *ModelPricing `json:"pricing,omitempty"`
}
ModelInfo contains basic model metadata.
type ModelPricing ¶ added in v1.5.1
type ModelPricing struct {
InputPerToken float64 `json:"input_per_token"`
OutputPerToken float64 `json:"output_per_token"`
CacheReadPerToken float64 `json:"cache_read_per_token"`
CacheWritePerToken float64 `json:"cache_write_per_token"`
}
ModelPricing defines per-token cost rates in USD. Set rates to 0 for categories that don't apply.