agent

package
v0.0.0-...-4c5b182 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2026 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CacheControlTypeEphemeral indicates content should be cached but not stored permanently
	CacheControlTypeEphemeral = "ephemeral"
)

Cache control type constants

Variables

View Source
var (
	// ErrTooLarge indicates the request exceeds size limits
	ErrTooLarge = errors.New("request too large")

	// ErrOverloaded indicates the service is temporarily overloaded
	ErrOverloaded = errors.New("service overloaded")

	// ErrRemoteServerError indicates a remote server failure
	ErrRemoteServerError = errors.New("server error")

	// ErrRateLimit indicates rate limiting by the service
	ErrRateLimit = errors.New("rate limit exceeded")

	// ErrMaxToolIterations indicates the maximum number of tool iterations was reached
	ErrMaxToolIterations = errors.New("max tool iterations reached")

	// ErrTerminateLoop is a sentinel error that indicates that the agent should terminate the loop.
	ErrTerminateLoop = errors.New("terminate loop")
)

Standard error types for agent operations

Functions

func JSONSchema

func JSONSchema[T any]() string

func ToolCallID

func ToolCallID(ctx context.Context) (string, bool)

ToolCallID returns the ID of the tool call that is currently being executed.

Types

type Agent

type Agent struct {
	// contains filtered or unexported fields
}

func New

func New(opts Opts) (*Agent, error)

func (*Agent) Loop

func (a *Agent) Loop(ctx context.Context, messages []Message, interjections func() []Message) (*MessagesResponse, error)

Loop runs the agent in a loop, generating messages and executing tools. It returns the final response from the LLM. It returns an error if the agent fails to generate a message or execute a tool.

The interjections function is called after each message is generated, and can be used to add additional messages to the conversation.

It only returns when the LLM returns a response with no tool uses, or MaxToolIterations is reached, or if a tool returns ErrTerminateLoop.

On error, the function returns both the last response (if any) and the error, allowing callers to access any partial results generated before the failure.

The context is propagated to the tool execution functions, so it can be used to cancel async tool executions even if this function returns.

type CacheControl

type CacheControl struct {
	Type string `json:"type"` // Type of cache control (e.g. "ephemeral")
}

CacheControl represents caching directives for message content. It defines how a message should be cached by the LLM provider to optimize token usage and response times in subsequent interactions.

func (*CacheControl) Clone

func (src *CacheControl) Clone() *CacheControl

Clone makes a deep copy of CacheControl. The result aliases no memory with the original.

type Content

type Content []MessageContent

func (Content) LossyText

func (c Content) LossyText() string

LossyText returns just the text content of the message content. It is lossy because it may lose things like images, thinking, tool use, etc.

type ContentType

type ContentType string

ContentType defines the type of content in a message

const (
	// ContentTypeText represents plain text content
	ContentTypeText ContentType = "text"

	// ContentTypeToolUse represents a tool being used
	ContentTypeToolUse ContentType = "tool_use"

	// ContentTypeToolResult represents the results of a tool execution
	ContentTypeToolResult ContentType = "tool_result"

	// ContentTypeThinking represents thinking/reasoning content (for Claude Sonnet)
	ContentTypeThinking ContentType = "thinking"

	// ContentTypeRedactedThinking represents redacted thinking content
	ContentTypeRedactedThinking ContentType = "redacted_thinking"

	// ContentTypeImage represents an image
	ContentTypeImage ContentType = "image"
)

Content types for message content

type FakeLLMClient

type FakeLLMClient struct {

	// RequestHistory stores all requests made to this client
	RequestHistory []MessagesRequest

	// ResponseDelay adds artificial delay to simulate network latency
	ResponseDelay time.Duration

	// DefaultResponse is used when responses slice is exhausted
	DefaultResponse *MessagesResponse

	// DefaultError is used when errors slice is exhausted (after DefaultResponse)
	DefaultError error

	// TokenCounter function for custom token counting logic
	TokenCounter func(req MessagesRequest) int

	// OnRequest is called for each request, allowing custom behavior
	OnRequest func(ctx context.Context, req MessagesRequest) (*MessagesResponse, error)
	// contains filtered or unexported fields
}

FakeLLMClient provides a configurable fake LLM client for testing. It can simulate various LLM behaviors including tool calls, errors, and delays.

FakeLLMClient is more feature-rich than mockLLMClient and provides:

  • Custom request handlers via OnRequest
  • Response delays to simulate network latency
  • Request history tracking
  • Builder pattern for easy configuration
  • Default responses when configured responses are exhausted
  • Token counting support

Usage with builder:

client := NewFakeLLMClient().
    WithTextResponse("Hello").
    WithToolCallResponse("my_tool", map[string]any{"arg": "value"}).
    WithError(errors.New("rate limited")).
    WithDelay(100 * time.Millisecond).
    Build()

Usage with custom handler:

client := &FakeLLMClient{
    OnRequest: func(ctx context.Context, req MessagesRequest) (*MessagesResponse, error) {
        // Custom logic based on request
        return &MessagesResponse{...}, nil
    },
}

func (*FakeLLMClient) CountTokens

func (f *FakeLLMClient) CountTokens(ctx context.Context, req MessagesRequest) (int, error)

CountTokens implements the TokenCounter interface

func (*FakeLLMClient) CreateMessages

func (f *FakeLLMClient) CreateMessages(ctx context.Context, req MessagesRequest, onUpdate func(MessagesResponse)) (MessagesResponse, error)

CreateMessages implements the LLMClient interface

func (*FakeLLMClient) GetCallCount

func (f *FakeLLMClient) GetCallCount() int

GetCallCount returns the number of times CreateMessages was called

func (*FakeLLMClient) GetLastRequest

func (f *FakeLLMClient) GetLastRequest() *MessagesRequest

GetLastRequest returns the most recent request, or nil if no requests

func (*FakeLLMClient) Reset

func (f *FakeLLMClient) Reset()

Reset clears the call count and request history

type FakeLLMClientBuilder

type FakeLLMClientBuilder struct {
	// contains filtered or unexported fields
}

FakeLLMClientBuilder provides a fluent interface for building FakeLLMClient instances

func NewFakeLLMClient

func NewFakeLLMClient() *FakeLLMClientBuilder

NewFakeLLMClient creates a new builder for FakeLLMClient

func (*FakeLLMClientBuilder) Build

func (b *FakeLLMClientBuilder) Build() *FakeLLMClient

Build returns the configured FakeLLMClient

func (*FakeLLMClientBuilder) WithDefaultError

func (b *FakeLLMClientBuilder) WithDefaultError(err error) *FakeLLMClientBuilder

WithDefaultError sets the default error when configured responses are exhausted

func (*FakeLLMClientBuilder) WithDefaultResponse

func (b *FakeLLMClientBuilder) WithDefaultResponse(resp MessagesResponse) *FakeLLMClientBuilder

WithDefaultResponse sets the default response when configured responses are exhausted

func (*FakeLLMClientBuilder) WithDelay

WithDelay adds response delay

func (*FakeLLMClientBuilder) WithError

func (b *FakeLLMClientBuilder) WithError(err error) *FakeLLMClientBuilder

WithError adds an error to return at the corresponding call

func (*FakeLLMClientBuilder) WithOnRequest

WithOnRequest sets a custom request handler

func (*FakeLLMClientBuilder) WithResponse

WithResponse adds a response to return

func (*FakeLLMClientBuilder) WithTextResponse

func (b *FakeLLMClientBuilder) WithTextResponse(text string) *FakeLLMClientBuilder

WithTextResponse adds a simple text response

func (*FakeLLMClientBuilder) WithToolCallResponse

func (b *FakeLLMClientBuilder) WithToolCallResponse(toolName string, args map[string]any) *FakeLLMClientBuilder

WithToolCallResponse adds a response with a tool call

type Hooks

type Hooks struct {
	// BeforeRequest is called just before sending a request to the LLM.
	// It can be used to modify or log the request, or to cancel the request by returning an error.
	BeforeRequest func(ctx context.Context, mr MessagesRequest) error

	// OnResponse is called immediately after receiving a response from the LLM,
	// before any tool calls are processed.
	// It can be used to log responses or modify them before further processing.
	OnResponse func(ctx context.Context, resp MessagesResponse) error

	// OnStreamingResponse is called during streaming responses with incremental updates.
	// It receives the full accumulated response for each update during streaming.
	OnStreamingResponse func(ctx context.Context, resp MessagesResponse)

	// BeforeToolRun is called just before executing a tool.
	// It can be used to validate or log tool calls, or to prevent execution by returning an error.
	// If an error is returned, the tool will not be executed and the error will be returned to the agent.
	BeforeToolRun func(ctx context.Context, toolID, toolName string, inputJSON json.RawMessage) error

	// AfterToolRun is called after a tool has been executed, with the result or error.
	// It can be used to log or modify tool results before they're sent back to the LLM.
	AfterToolRun func(ctx context.Context, toolID, toolName string, inputJSON json.RawMessage, output string, other []MessageContent, outErr error) error

	// OnToolResponse is called after a tool has been executed, with the result or error.
	// It can be used to log or modify tool results before they're sent back to the LLM.
	OnToolResponse func(ctx context.Context, toolResponse *Message, err error) error
}

Hooks defines callback functions that can be registered to intercept and modify agent behavior at various points in the conversation lifecycle. All hook functions are optional and can be nil if not needed.

These hooks allow for customization of the agent's behavior without modifying the core agent implementation. This is useful for adding logging, metrics, custom validation, or integration with other systems.

type LLMClient

type LLMClient interface {
	// CreateMessages sends a request to the LLM and returns the response.
	// It must handle rate limiting, context cancellation, and other errors
	// as specified above. All provider-specific errors must be wrapped using
	// the appropriate error types defined in this package.
	//
	// If onUpdate is provided, it will be called with incremental updates as the
	// response is generated (streaming). The callback receives the full accumulated
	// response for each update. If nil, the method behaves non-streaming.
	CreateMessages(ctx context.Context, req MessagesRequest, onUpdate func(MessagesResponse)) (MessagesResponse, error)
}

LLMClient represents a client that can process messages and return responses. Implementations must handle:

  • Rate limiting: Return ErrRateLimit wrapped in a RateLimitError containing retry duration. Example: return &RateLimitError{RetryAfter: 30 * time.Second, Err: fmt.Errorf("%w: %v", ErrRateLimit, err)}

  • Context cancellation: Respect context cancellation and return ctx.Err() directly. Example: if ctx.Err() != nil { return MessagesResponse{}, ctx.Err() }

  • Request size limits: Return ErrTooLarge wrapped with additional context. Example: return MessagesResponse{}, fmt.Errorf("%w: request exceeds size limit", ErrTooLarge)

  • Service overload: Return ErrOverloaded wrapped with additional context. Example: return MessagesResponse{}, fmt.Errorf("%w: service temporarily unavailable", ErrOverloaded)

  • Message conversion: Convert between implementation-specific and agent message types while preserving all required fields and maintaining proper JSON serialization.

  • Token counting: Track and report token usage accurately in Usage struct.

The interface is designed to be implementation-agnostic, allowing different LLM providers to be used interchangeably. Implementations must properly wrap their native errors using the defined error types to ensure consistent error handling across different providers.

type Message

type Message struct {
	Role    Role    `json:"role"`    // Role of the message sender (e.g. "user", "assistant")
	Content Content `json:"content"` // Content blocks for the message
}

Message represents a chat message in a conversation with an LLM. It contains the role of the sender (system, user, assistant, or tool) and one or more content blocks that can have different types (text, tool use, etc.).

func (*Message) Clone

func (src *Message) Clone() *Message

Clone makes a deep copy of Message. The result aliases no memory with the original.

type MessageContent

type MessageContent struct {
	// Type indicates the kind of content (text, tool_use, tool_result, thinking, etc.)
	Type ContentType `json:"type"`

	// Thinking contains the reasoning/thinking content when Type is ContentTypeThinking
	// This is primarily used with Claude Sonnet and other models supporting thinking chains
	Thinking string `json:"thinking,omitempty"`

	// Signature contains a cryptographic signature for the thinking block when used
	Signature string `json:"signature,omitempty"`

	// MediaType is used to specify what type of image is being sent.
	// Available types are "image/png", "image/jpeg", "image/webp", and "image/gif".
	MediaType string `json:"media_type,omitempty"`

	// Data contains base64 encoded data when Type is ContentTypeImage.
	Data json.RawMessage `json:"data,omitempty"`

	// RedactedThinking contains the redacted thinking content when Type is ContentTypeRedactedThinking
	RedactedThinking string `json:"redacted_thinking,omitempty"`

	// Text contains the plain text content when Type is ContentTypeText
	Text string `json:"text,omitempty"`

	// ToolUse contains tool use information when Type is ContentTypeToolUse
	ToolUse *ToolUse `json:"tool_use,omitempty"`

	// ToolResults contains tool execution results when Type is ContentTypeToolResult
	ToolResults *ToolResult `json:"tool_results,omitempty"`

	// CacheControl contains optional caching directives for this content
	CacheControl *CacheControl `json:"cache_control,omitempty"`
}

MessageContent represents different types of content that can appear in a message. The Type field determines which other fields are populated and used.

func NewImageContent

func NewImageContent(mediaType string, base64Data string) MessageContent

NewImageContent creates a new image content with base64 encoded data

func NewTextContent

func NewTextContent(text string) MessageContent

NewTextContent creates a new text content

func NewToolResultContent

func NewToolResultContent(name, toolCallID, output string, isError bool) MessageContent

NewToolResultContent creates a new tool result content

func NewToolUseContent

func NewToolUseContent(id, name string, input json.RawMessage) MessageContent

NewToolUseContent creates a new tool use content

func (*MessageContent) Clone

func (src *MessageContent) Clone() *MessageContent

Clone makes a deep copy of MessageContent. The result aliases no memory with the original.

func (*MessageContent) GetText

func (c *MessageContent) GetText() string

GetText returns the text content of the message

type MessagesRequest

type MessagesRequest struct {
	// System is the system prompt that guides the LLM's behavior.
	// This provides high-level instructions to the model about its role and constraints.
	System string `json:"system"`

	// MaxTokens limits the number of tokens the LLM can generate in its response.
	// A value of 0 means the default model limit will be used.
	MaxTokens int `json:"max_tokens"`

	// Messages contains the conversation history in chronological order.
	// This includes previous user messages, assistant responses, and tool interactions.
	Messages []Message `json:"messages"`

	// Tools defines the tools available for the LLM to use in its response.
	// These are presented to the model as capabilities it can invoke.
	Tools []ToolDefinition `json:"tools"`

	// ToolChoice specifies how tools should be chosen:
	// - If nil or Type="auto": Let the LLM decide which tool to use (if any)
	// - If Type="tool" and Name is set: Force the LLM to use that specific tool
	// - If Type="any": Force the LLM to use any tool (implementation-specific)
	ToolChoice *ToolChoice `json:"tool_choice,omitempty"`

	// ThinkingMode enables the LLM to show its reasoning process.
	// This is only supported by certain models (e.g., Claude Sonnet).
	// The provider should ignore this field if it does not support it.
	ThinkingMode bool `json:"thinking_mode,omitempty"`

	// ThinkingTokens specifies how many tokens to allocate for thinking/reasoning.
	// Only applies when ThinkingMode is true. A value of 0 means the default (typically 1024).
	// The provider should ignore this field if it does not support ThinkingMode.
	ThinkingTokens int `json:"thinking_tokens,omitempty"`
}

MessagesRequest represents a request to create messages through an LLM service. It contains all the necessary information to generate a response, including the conversation history, available tools, and configuration parameters.

This struct serves as the primary input to LLMClient.CreateMessages() and encapsulates everything needed to generate an AI response, whether using tools or just text. The fields control both what content the LLM considers and how it should respond.

func (*MessagesRequest) Clone

func (src *MessagesRequest) Clone() *MessagesRequest

Clone makes a deep copy of MessagesRequest. The result aliases no memory with the original.

type MessagesResponse

type MessagesResponse struct {
	// ID is the ID of the response.
	ID string `json:"id"`

	// StopReason is the reason the LLM stopped generating content.
	StopReason string `json:"stop_reason"`

	// Content contains the actual response content from the LLM,
	// which may include text, tool calls, or other content types.
	// The format of this content matches the MessageContent struct and can
	// contain multiple types of responses in a single message.
	Content Content `json:"content"`

	// Usage provides statistics about token consumption and caching metrics
	// from the LLM service, including input, output, and cache-related tokens.
	Usage Usage `json:"usage"`

	// TimeToFirstToken is the time it took for the first token to be generated.
	TimeToFirstToken time.Duration `json:"time_to_first_token"`

	// ResponseTime is the total time it took for the response to be generated.
	ResponseTime time.Duration `json:"response_time"`
}

MessagesResponse represents a response from creating messages via an LLM service. It contains the generated content from the model along with usage statistics for token consumption and caching metrics.

func (*MessagesResponse) Clone

func (src *MessagesResponse) Clone() *MessagesResponse

Clone makes a deep copy of MessagesResponse. The result aliases no memory with the original.

type Opts

type Opts struct {
	// Name is the unique identifier for this agent instance.
	// It is only used for logging and metrics.
	Name string

	// SystemPrompt is the system instruction that guides the LLM's behavior.
	// Required - must be non-empty.
	SystemPrompt string

	// Client is the LLM service implementation to use for generating responses.
	// Required - must be a valid implementation of the LLMClient interface.
	Client LLMClient

	// Hooks provides optional callback functions for customizing agent behavior
	// at various points in the conversation lifecycle.
	Hooks Hooks

	// ToolProvider is an optional function that provides tools dynamically on each request.
	// If set, it will be called before each LLM request to get the current list of tools.
	// The tools returned by this function will be merged with the Tools list.
	ToolProvider func() []*Tool

	// Logf is the logging function to use. If nil, defaults to log.Printf.
	// Can be used to integrate with custom logging systems.
	Logf logger.Logf

	// ThinkingTokens specifies how many tokens to allocate for thinking/reasoning.
	// Only applies when ThinkingMode is true. A value of 0 means to use the default value.
	ThinkingTokens int

	// ForceTools restricts the agent to only using tools.
	// When true, the agent will not use the LLM to generate responses.
	ForceTools bool

	// MaxTokens limits the number of tokens in the LLM's response.
	// A value of 0 means to use the default value.
	MaxTokens int

	// MaxContextSize limits how large the agent's context can get before a loop is terminated.
	// If 0, no limit is applied.
	MaxContextSize int

	// MaxToolIterations is the maximum number of iterations for a call to
	// [Agent.Loop]. If 0, no limit is applied.
	MaxToolIterations int
}

Opts defines the configuration options for creating a new Agent. It controls the agent's behavior, capabilities, and integration with LLM services.

type RateLimitError

type RateLimitError struct {
	// RetryAfter indicates how long to wait before retrying the request
	RetryAfter time.Duration
	// Err is the underlying error, typically wrapping ErrRateLimit
	Err error
}

RateLimitError represents a rate limiting error from an LLM service. It includes information about when to retry the request.

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

Error implements the error interface and provides a formatted error message

func (*RateLimitError) Unwrap

func (e *RateLimitError) Unwrap() error

Unwrap implements the errors.Unwrap interface to allow errors.Is/As checking

type Role

type Role string
const (
	// RoleSystem represents a system message that guides the AI's behavior
	RoleSystem Role = "system"

	// RoleUser represents a message from the user
	RoleUser Role = "user"

	// RoleAssistant represents a message from the AI assistant
	RoleAssistant Role = "assistant"

	// RoleTool represents a message from a tool execution
	RoleTool Role = "tool"
)

Message role constants

type TokenCounter

type TokenCounter interface {
	// CountTokens analyzes the request and returns the estimated number of tokens it would use.
	// This is useful for:
	// 1. Estimating costs before making expensive API calls
	// 2. Preventing requests that would exceed token limits
	// 3. Optimizing prompts by analyzing token usage
	//
	// If the implementation cannot count tokens accurately, it should return an error.
	CountTokens(ctx context.Context, req MessagesRequest) (int, error)
}

TokenCounter is an optional interface that can be implemented by an LLMClient to estimate the token usage and cost of a request before sending it to the LLM service. This allows for pre-flight checks on token limits and cost estimations.

type Tool

type Tool struct {
	// Name is the name of the tool.
	Name string
	// Desc is the description of the tool.
	Desc string

	// Schema is the JSON schema for the tool's input.
	Schema string

	// Handler is the function that will be called when the tool is used. It
	// must be set.
	Handler toolUseHandler
	// contains filtered or unexported fields
}

func NewTool

func NewTool[T any](name, desc string, handler ToolHandler[T]) *Tool

func NewToolFromSpec

func NewToolFromSpec[T any](spec ToolSpec[T]) *Tool

NewToolFromSpec creates a new content tool from a ContentToolSpec with a user-visible summary

func (*Tool) Clone

func (src *Tool) Clone() *Tool

Clone makes a deep copy of Tool. The result aliases no memory with the original.

func (*Tool) Summary

func (t *Tool) Summary(inputJSON json.RawMessage) string

type ToolChoice

type ToolChoice struct {
	// Type determines the tool selection strategy:
	// - "auto": Let the LLM decide which tool to use (if any)
	// - "tool": Force the LLM to use the specific tool named in the Name field
	// - "any": Force the LLM to use any tool (implementation-specific behavior)
	Type string `json:"type"`

	// Name is the specific tool name to use when Type is "tool".
	// This field is required when Type is "tool" and ignored otherwise.
	Name string `json:"name"`
}

ToolChoice specifies how an LLM should choose tools during a conversation. It controls whether the LLM automatically selects appropriate tools or if it should be directed to use a specific named tool.

This struct is used in MessagesRequest to guide tool selection behavior, allowing for both autonomous tool selection by the LLM and forced usage of specific tools when needed for deterministic behavior.

func (*ToolChoice) Clone

func (src *ToolChoice) Clone() *ToolChoice

Clone makes a deep copy of ToolChoice. The result aliases no memory with the original.

type ToolDefinition

type ToolDefinition struct {
	Name        string          `json:"name"`         // Name of the tool
	Description string          `json:"description"`  // Human-readable description of what the tool does
	InputSchema json.RawMessage `json:"input_schema"` // JSON schema describing the input parameters
}

ToolDefinition represents the definition of a tool that can be provided to an LLM. It contains the metadata needed for the LLM to understand the tool's purpose and how to properly invoke it with correct parameters.

func (*ToolDefinition) Clone

func (src *ToolDefinition) Clone() *ToolDefinition

Clone makes a deep copy of ToolDefinition. The result aliases no memory with the original.

type ToolHandler

type ToolHandler[Req any] func(ctx context.Context, req Req) (string, []MessageContent, error)

ToolHandler is a type-safe version of ToolHandler that works with a specific request type. It handles type conversion and validation automatically when used with JSONHandler. The Req type parameter defines the structure expected for the tool's input parameters.

This allows for type-safe tool implementations with automatic schema validation based on the Go type system. It's the preferred way to implement new tools.

func (ToolHandler[Req]) Handle

func (h ToolHandler[Req]) Handle(ctx context.Context, toolUse *ToolUse) (string, []MessageContent, error)

type ToolResult

type ToolResult struct {
	Name       string `json:"tool_name"`    // Name of the tool
	ToolCallID string `json:"tool_call_id"` // ID of the tool call these results are for
	Output     string `json:"output"`       // Output from the tool
	Error      bool   `json:"error"`        // Whether this output represents an error
}

ToolResult represents the results of a tool execution. It contains the output from executing a tool, along with information about whether the execution resulted in an error.

func (*ToolResult) Clone

func (src *ToolResult) Clone() *ToolResult

Clone makes a deep copy of ToolResult. The result aliases no memory with the original.

type ToolSpec

type ToolSpec[T any] struct {
	Name        string              // Name of the tool
	Description string              // Full description for the LLM
	Summary     func(args T) string // Function to generate a summary of the tool invocation
	Handler     ToolHandler[T]      // The handler function for the tool
}

ToolSpec defines a content tool with a user-visible summary for better UX

type ToolUse

type ToolUse struct {
	ID    string          `json:"id"`    // Unique identifier for this tool use
	Name  string          `json:"name"`  // Name of the tool
	Input json.RawMessage `json:"input"` // Input parameters for the tool
}

ToolUse represents a tool being invoked by the LLM during a conversation. It contains the necessary information to identify and execute a specific tool with the provided input parameters.

func (*ToolUse) Clone

func (src *ToolUse) Clone() *ToolUse

Clone makes a deep copy of ToolUse. The result aliases no memory with the original.

type Usage

type Usage struct {
	InputTokens              int `json:"input_tokens"`
	OutputTokens             int `json:"output_tokens"`
	CacheCreationInputTokens int `json:"cache_creation_input_tokens"`
	CacheReadInputTokens     int `json:"cache_read_input_tokens"`
}

Usage represents token usage statistics

func (*Usage) Clone

func (src *Usage) Clone() *Usage

Clone makes a deep copy of Usage. The result aliases no memory with the original.

Directories

Path Synopsis
Package models contains constants for the models used in the application.
Package models contains constants for the models used in the application.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL