Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDefaultConfig ¶
func SetDefaultConfig(cfg Config)
SetDefaultConfig sets the instance-wide LLM settings (the `llm` block of the configuration). Fields an agent leaves empty fall back to them.
func WithUsageRecorder ¶ added in v0.5.0
func WithUsageRecorder(ctx context.Context, r *UsageRecorder) context.Context
WithUsageRecorder returns a context whose LLM calls are recorded by r.
Types ¶
type Client ¶
type Client interface {
Chat(ctx context.Context, messages []Message, opts ...Option) (*Response, error)
}
Client is the interface that all LLM providers must implement.
func NewAdapter ¶
NewAdapter creates a new `Client` by wrapping the specified LLM provider. Empty fields are filled from SetDefaultConfig.
type Message ¶
type Message struct {
Role Role `json:"role"`
Content string `json:"content"`
ToolCallID string `json:"tool_call_id,omitempty"`
ToolCall *llms.ToolCall `json:"tool_call,omitempty"`
}
Message represents a single message in a conversation.
type Option ¶
type Option func(*options)
Option is a functional option for the Chat method.
func WithToolChoice ¶
WithToolChoice sets the tool choice option for the LLM call.
type Response ¶
type Response struct {
Type ResponseType
Content string
ToolCall *llms.ToolCall
Usage Usage // tokens of this call, and its estimated cost
}
Response represents the output from an LLM chat call.
type ResponseType ¶
type ResponseType string
ResponseType indicates the type of the LLM's response.
const ( ResponseTypeText ResponseType = "text" ResponseTypeToolCall ResponseType = "tool_call" )
type Usage ¶ added in v0.5.0
type Usage struct {
InputTokens int `json:"inputTokens"`
OutputTokens int `json:"outputTokens"`
CostUSD float64 `json:"costUsd"` // 0 when the model has no configured price
Calls int `json:"calls"`
}
Usage counts the tokens of one or more LLM calls and their estimated cost.
type UsageRecorder ¶ added in v0.5.0
type UsageRecorder struct {
// contains filtered or unexported fields
}
UsageRecorder accumulates the usage of every LLM call made with a context that carries it, including calls made inside agent functions.
func RecorderFrom ¶ added in v0.5.0
func RecorderFrom(ctx context.Context) *UsageRecorder
RecorderFrom returns the recorder carried by ctx, or nil.
func (*UsageRecorder) Add ¶ added in v0.5.0
func (r *UsageRecorder) Add(u Usage)
Add records a call.
func (*UsageRecorder) Total ¶ added in v0.5.0
func (r *UsageRecorder) Total() Usage
Total returns everything recorded so far.