Documentation
¶
Index ¶
- Variables
- type Agent
- type AgentResponseKwargs
- type AgentResponseOpt
- type AgentSession
- type AgentStreamer
- type AssistantMessage
- type DeferredCallResult
- type DeferredToolCall
- type DeveloperMessage
- type Encoder
- type FeedbackGenerator
- type ImageAttachment
- type Message
- type Model
- type ModelLogger
- type ModelLoggingInfo
- type ModelResponse
- type ModelResponseCache
- type ModelResponseKwargs
- type ModelResponseOpt
- type ModelStreamer
- type OpaqueReasoningBlock
- type Parser
- type Pipeline
- type PipelineResponse
- type Skill
- type SystemMessage
- type Tool
- type ToolArgs
- func (args ToolArgs) AlignWithSchema(schema ToolSchema) error
- func (args ToolArgs) Clone() ToolArgs
- func (args ToolArgs) OptionalBool(key string, defaultVal bool) (bool, bool)
- func (args ToolArgs) OptionalFloat(key string, defaultVal float64) (float64, bool)
- func (args ToolArgs) OptionalInt(key string, defaultVal int) (int, bool)
- func (args ToolArgs) OptionalString(key string, defaultVal string) (string, bool)
- func (args ToolArgs) RequiredBool(key string) bool
- func (args ToolArgs) RequiredFloat(key string) float64
- func (args ToolArgs) RequiredInt(key string) int
- func (args ToolArgs) RequiredString(key string) string
- type ToolCall
- type ToolParam
- type ToolParamType
- type ToolResult
- type ToolResultMessage
- type ToolSchema
- type Usage
- type UserMessage
- type Validator
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidResponse = errors.New("llm produced an invalid response")
)
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent interface {
Session() AgentSession
SetSession(AgentSession)
SetMaxIterations(int)
SetToolCatalogue([]Tool)
SetSkillCatalogue([]Skill)
Run(context.Context, string, ...AgentResponseOpt) error
Resume(context.Context, []DeferredCallResult, ...AgentResponseOpt) error
}
type AgentResponseKwargs ¶
type AgentResponseKwargs struct {
Streamer AgentStreamer
}
func GetAgentResponseKwargs ¶
func GetAgentResponseKwargs(opts []AgentResponseOpt) AgentResponseKwargs
type AgentResponseOpt ¶
type AgentResponseOpt func(*AgentResponseKwargs)
func WithStreamActions ¶
func WithStreamActions(streamer AgentStreamer) AgentResponseOpt
type AgentSession ¶
type AgentSession struct {
// The prompt that tells the agent how to interact with the agent loop and react loop,
// usually does not need to be changed.
AgentPrompt string
// The prompt telling the agent specifically about its task,
// if not specified will tell the agent to be a generalist.
TaskPrompt string
// The prompt telling the agent how to act / speak,
// if not specified will speak neutrally and refer to itself as AI Assistant.
PersonalityPrompt string
// The messages, excluding system and other special messages.
CoreMessages []Message
// The current tool calls that have been deferred, with their validated args.
CurrentDeferredToolCalls []DeferredToolCall
// The names of the skills that should currently be active.
ActiveSkillNames []string
// PromptFragments are extra blocks of keyed text rendered in the head state,
// ordered by key. A tool can add or overwrite a fragment by returning it in
// its result; returning a key with an empty value removes that fragment.
PromptFragments map[string]string
}
An agent session describes the state of an agent at the current point in time, avoiding any specific logic or details of skills.
func DefaultAgentSession ¶
func DefaultAgentSession() AgentSession
func (AgentSession) Clone ¶
func (a AgentSession) Clone() AgentSession
type AgentStreamer ¶
type AgentStreamer interface {
OnMessageComplete(Message)
}
type AssistantMessage ¶ added in v0.10.0
type AssistantMessage struct {
Content string
// Turn-level opaque reasoning-continuation state. When the message is
// replayed to the model, these blocks are emitted before Content and before
// any tool calls. See OpaqueReasoningBlock.
Reasoning []OpaqueReasoningBlock
ToolCalls []ToolCall
}
AssistantMessage represents a message from the model to the user.
func (AssistantMessage) Eq ¶ added in v0.10.0
func (m AssistantMessage) Eq(other Message) bool
func (AssistantMessage) String ¶ added in v0.10.0
func (m AssistantMessage) String() string
type DeferredCallResult ¶
type DeferredCallResult struct {
CallID string
Content string
// PromptFragments behaves as documented on ToolResult.PromptFragments: a
// non-empty value adds or overwrites the fragment, an empty value removes it,
// and keys that are not present are left unchanged.
PromptFragments map[string]string
Err error
}
DeferredCallResult is what results from your code (not the agent framework) calling the tool.
type DeferredToolCall ¶
DeferredToolCall describes a call to a named tool that the agent framework cannot run, so it has deferred to your code.
type DeveloperMessage ¶ added in v0.10.0
type DeveloperMessage struct {
Content string
}
DeveloperMessage represents a message from the developer (basically system) to the model.
func (DeveloperMessage) Eq ¶ added in v0.10.0
func (m DeveloperMessage) Eq(other Message) bool
func (DeveloperMessage) String ¶ added in v0.10.0
func (m DeveloperMessage) String() string
type Encoder ¶ added in v0.9.0
Encoder encodes a structured piece of data into a set of messages for an LLM.
type FeedbackGenerator ¶ added in v0.6.0
type FeedbackGenerator interface {
FormatFeedback(AssistantMessage, error) string
}
FeedbackGenerator takes an error and converts it to a piece of text feedback to send to the LLM.
type ImageAttachment ¶ added in v0.7.0
ImageAttachment is an image that is attached as additional information to a message.
func (*ImageAttachment) ToBase64Encoded ¶ added in v0.7.0
func (i *ImageAttachment) ToBase64Encoded(useCompression bool) (string, error)
type Message ¶
type Message interface {
String() string
Eq(Message) bool
// contains filtered or unexported methods
}
Message is a sum type of the different messages that can be sent to Models.
type Model ¶
type Model interface {
// Responds to a set of input messages.
Respond(context.Context, []Message, ...ModelResponseOpt) (ModelResponse, error)
}
Model defines an interface to an LLM.
type ModelLogger ¶ added in v0.7.0
type ModelLogger interface {
ModelLog(ModelLoggingInfo) error
}
ModelLogger specifies a method of logging a call to a model.
type ModelLoggingInfo ¶ added in v0.6.0
type ModelLoggingInfo struct {
InputMessages []Message
ResultMessage AssistantMessage
Usage Usage
Err error
Duration time.Duration
}
ModelLoggingInfo contains all information about a model interaction to be logged. It includes input messages, output messages, usage statistics, and any error that occurred.
type ModelResponse ¶ added in v0.8.0
type ModelResponse struct {
// The response to the input messages.
Message AssistantMessage
// The usage of making this call.
// This may be the sum of multiple LLM calls.
Usage Usage
}
func (ModelResponse) IncludingUsage ¶ added in v0.8.0
func (r ModelResponse) IncludingUsage(u Usage) ModelResponse
Utility to include another usage object in this response object
func (ModelResponse) OnlyUsage ¶ added in v0.8.0
func (r ModelResponse) OnlyUsage() ModelResponse
Utility to allow you to return the usage but 0 value messages when an error occurs.
type ModelResponseCache ¶ added in v0.6.0
type ModelResponseKwargs ¶ added in v0.10.0
type ModelResponseKwargs struct {
Streamer ModelStreamer
OutputFormat any
ToolSchemas []ToolSchema
}
func GetModelResponseKwargs ¶ added in v0.10.0
func GetModelResponseKwargs(opts ...ModelResponseOpt) ModelResponseKwargs
type ModelResponseOpt ¶ added in v0.10.0
type ModelResponseOpt func(*ModelResponseKwargs)
func WithOutputFormat ¶ added in v0.10.0
func WithOutputFormat(format any) ModelResponseOpt
Set the output format (structured output). This should be a struct, as it will be processed into the correct API model output format by the model itself.
func WithStreamResponse ¶ added in v0.9.0
func WithStreamResponse(streamer ModelStreamer) ModelResponseOpt
Stream the model's response to the streamer. This will override any previously set streamers.
func WithToolSchemas ¶ added in v0.10.0
func WithToolSchemas(schemas ...ToolSchema) ModelResponseOpt
Add the provided tool schemas (additive, not replace) to the model. If there is at least one tool schema, tool calling will be enabled, so the model needs to support tool calling in this case.
type ModelStreamer ¶ added in v0.10.0
type ModelStreamer interface {
OnMessageBegin()
OnMessageText(text string)
OnMessageReset()
}
type OpaqueReasoningBlock ¶
type OpaqueReasoningBlock struct {
// Stable identifier of the wire format and model that produced this block,
// e.g. "anthropic/claude-sonnet-4-20250514" or "openai-responses/gpt-5". A
// block is only replayed to a backend reporting exactly this FormatFamily.
FormatFamily string `json:"format_family"`
// Provider correlation id (OpenAI Responses "rs_..."), or "".
ID string `json:"id,omitempty"`
// Provider integrity token (Anthropic thinking signature, Gemini
// thoughtSignature), or "".
Sig string `json:"sig,omitempty"`
// The block body, handed back verbatim: Anthropic signed thinking text or
// redacted data, OpenAI Responses encrypted_content, or "". Never
// transformed - provider signatures are computed over it.
Payload string `json:"payload,omitempty"`
}
OpaqueReasoningBlock is opaque, provider-specific reasoning-continuation state that a model backend emits and needs handed back to that same backend on the next turn, so a tool-calling agent keeps the model's chain of thought across steps (Anthropic extended thinking, OpenAI Responses reasoning items, Gemini thought signatures).
It is never interpreted by client code. Only the model backend whose FormatFamily matches assigns meaning to the fields; any other backend drops the block when replaying the conversation. Blocks are only produced by a backend that was built WithStoreReasoning.
type Parser ¶ added in v0.9.0
Parser converts the LLM response into a structured piece of output data. When the LLM response is invalid, it should return ErrInvalidResponse (or an error joined on that).
type Pipeline ¶ added in v0.9.0
type Pipeline[T, U any] interface { Call(context.Context, T) (PipelineResponse[U], error) }
Pipeline transforms input of type T into output of type U using an LLM. It handles the encoding of input, interaction with the LLM, and decoding of output.
type PipelineResponse ¶ added in v0.10.0
type PipelineResponse[U any] struct { // The parsed and validated result. Result U // The usage of making this call. // This may be the sum of multiple LLM calls. Usage Usage }
func (PipelineResponse[U]) IncludingUsage ¶ added in v0.10.0
func (r PipelineResponse[U]) IncludingUsage(u Usage) PipelineResponse[U]
Utility to include another usage object in this response object
func (PipelineResponse[U]) OnlyUsage ¶ added in v0.10.0
func (r PipelineResponse[U]) OnlyUsage() PipelineResponse[U]
Utility to allow you to return the usage but 0 value messages when an error occurs.
type SystemMessage ¶ added in v0.10.0
type SystemMessage struct {
Content string
}
SystemMessage represents a message from the system to the model, to set up its task, personality.
func (SystemMessage) Eq ¶ added in v0.10.0
func (m SystemMessage) Eq(other Message) bool
func (SystemMessage) String ¶ added in v0.10.0
func (m SystemMessage) String() string
type Tool ¶
type Tool struct {
// How should the LLM call the tool?
Schema ToolSchema
// How should the agent framework run the tool.
// If not specified, the agent framework will break the loop and defer.
Call func(context.Context, ToolArgs) (ToolResult, error)
}
Tool describes a tool that is available to the agent, encompassing both directly executable and deferred tools.
type ToolArgs ¶
ToolArgs are the arguments an LLM has tried to call a tool with.
func (ToolArgs) AlignWithSchema ¶
func (args ToolArgs) AlignWithSchema(schema ToolSchema) error
Takes the raw arguments (from json decoding) and modifies / validates them in-place to make them work for the schema. For example, converts floats to ints when the schema specifies int. Does NOT check for extra args the llm supplied that were not asked for.
func (ToolArgs) OptionalBool ¶
func (ToolArgs) OptionalFloat ¶
func (ToolArgs) OptionalInt ¶
func (ToolArgs) OptionalString ¶
func (ToolArgs) RequiredBool ¶
func (ToolArgs) RequiredFloat ¶
func (ToolArgs) RequiredInt ¶
func (ToolArgs) RequiredString ¶
type ToolCall ¶ added in v0.10.0
type ToolCall struct {
ID string
Tool string
Args ToolArgs
// Opaque reasoning-continuation state tied to this specific call. When the
// message is replayed to the model, these blocks are emitted immediately
// before this call. See OpaqueReasoningBlock.
Reasoning []OpaqueReasoningBlock `json:"reasoning,omitempty"`
}
type ToolParam ¶
type ToolParam struct {
Name string
Description string
Type ToolParamType
Required bool
}
ToolParam describes a parameter that an agent may pass to a tool.
type ToolParamType ¶
type ToolParamType uint8
ToolParamType defines a type for a parameter of a tool call.
const ( ToolParamInt ToolParamType = iota ToolParamFloat ToolParamString )
type ToolResult ¶
type ToolResult struct {
Content string
// PromptFragments are prompt fragments to apply to the agent session, keyed
// by fragment key. A non-empty value adds or overwrites that fragment; an
// empty value removes it. Keys that are not present are left unchanged.
PromptFragments map[string]string
}
ToolResult is what a Tool.Call returns when it is run by the agent framework.
type ToolResultMessage ¶ added in v0.10.0
ToolResultMessage represents a result from calling a tool.
func (ToolResultMessage) Eq ¶ added in v0.10.0
func (m ToolResultMessage) Eq(other Message) bool
func (ToolResultMessage) String ¶ added in v0.10.0
func (m ToolResultMessage) String() string
type ToolSchema ¶ added in v0.10.0
ToolSchema specifies how an LLM should call a tool.
type UserMessage ¶ added in v0.10.0
type UserMessage struct {
Content string
Images []ImageAttachment
}
UserMessage represents a message from the user to the model.
func (UserMessage) Eq ¶ added in v0.10.0
func (m UserMessage) Eq(other Message) bool
func (UserMessage) String ¶ added in v0.10.0
func (m UserMessage) String() string
type Validator ¶ added in v0.9.0
Validator takes a parsed LLM response and validates it against the input. When the LLM response is invalid, it should return ErrInvalidResponse (or an error joined on that).