assistants

package
v1.0.178 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package assistants provides the core agent loop: system prompt assembly, LLM invocation, parallel tool calling, structured output parsing, callbacks and message history.

An Assistant is generic over its output type, which must implement chatmodel.ContentProvider. The type's JSON schema is what steers the model: it is sent as a provider response format when the provider supports one, and appended to the system prompt otherwise.

Quick example

// The output type. jsonschema tags are the model's instructions.
type Answer struct {
    Text string `json:"text" jsonschema:"required,title=Text,description=The answer."`
}

func (a Answer) GetContent() string { return llmutils.ToJSON(a) }

// A factory resolves the model from configuration (see pkg/llmfactory).
fac, err := llmfactory.Load("llm.yaml")
if err != nil {
    return err
}

agent := assistants.NewAssistant[Answer](fac,
    prompts.NewPromptTemplate("You are a concise assistant.", nil),
    assistants.WithMessageStore(store.NewMemoryStore()),
).
    WithName("researcher"). // binds to assistant_models.researcher
    WithDescription("Answers factual questions.")

// Every run requires a ChatContext; without one Run fails with
// chatmodel.ErrInvalidChatContext.
chatCtx := chatmodel.NewChatContext("user-123", "", nil)
ctx := chatmodel.WithChatContext(context.Background(), chatCtx)

var out Answer
resp, err := agent.Run(ctx, &assistants.CallInput{Input: "Say hi"}, &out)

Tools

Tools are attached with Assistant.WithTools and are keyed by lower-cased name. All tools the model requests in one turn are executed concurrently, so a tool's Call must be safe for concurrent use. A tool error other than chatmodel.ErrFailedUnmarshalInput is serialized back to the model as a tool response so it can recover, rather than aborting the run.

Delegation

NewAssistantTool wraps an assistant as a tools.ITool, which is how multi-agent flows are built: give the wrapper to a supervising assistant and its model decides when to delegate. Context, callbacks and per-call options flow downward; token usage is aggregated upward into Response.Usage.

Limits

Each run is bounded by DefaultMaxToolCalls, DefaultMaxMessages, DefaultMaxContentSize and DefaultMaxRetries, overridable per assistant or per call. Exceeding a limit fails the run with an error naming the assistant rather than truncating silently. A response that fails to parse into the output type is retried once: the unparsable answer stays in the history, followed by a request for JSON, and the same tools are offered.

See Documentation/assistants.md for the full option reference and the anatomy of a run, and Documentation/orchestration.md for multi-agent patterns.

Index

Constants

View Source
const (
	DefaultMaxToolCalls   = 50
	DefaultMaxMessages    = 100
	DefaultMaxContentSize = 500000
	DefaultMaxRetries     = 2
)

Variables

This section is empty.

Functions

func DefaultPromptProvider added in v0.17.130

func DefaultPromptProvider(ctx context.Context, list skills.Skills) (string, error)

DefaultPromptProvider renders the skills catalog appended to an assistant's system prompt: the name and description of each skill, plus instructions on when to activate one via the activate_skill tool. Override it per assistant with Assistant.WithSkillsPromptProvider.

func MapAssistants

func MapAssistants(list ...IAssistant) map[string]IAssistant

MapAssistants indexes the assistants by Name for dispatching by name in code-driven routing. Returns nil for an empty list.

Types

type Assistant

type Assistant[O chatmodel.ContentProvider] struct {
	OutputParser chatmodel.OutputParser[O]
	// contains filtered or unexported fields
}

Assistant class for chat assistants. This class provides the core functionality for handling chat interactions, including managing memory, generating system prompts, and obtaining responses from a language model.

func NewAssistant

func NewAssistant[O chatmodel.ContentProvider](
	llmFactory llmfactory.Factory,
	sysprompt prompts.FormatPrompter,
	options ...Option) *Assistant[O]

NewAssistant initializes the AgentAgent

func (*Assistant[O]) Call

func (a *Assistant[O]) Call(ctx context.Context, input *CallInput) (*Response, error)

Call runs the assistant and validates the output against O, discarding the parsed value. Use Run to obtain the typed result.

func (*Assistant[O]) CallMCP added in v0.3.11

func (a *Assistant[O]) CallMCP(ctx context.Context, input chatmodel.MCPInputRequest) (*mcp.PromptResponse, error)

CallMCP runs the assistant for an MCP prompt request. A non-empty input.ChatID is applied to the ChatContext on ctx, so an MCP client can continue an existing conversation. Output parsing is skipped and each choice is returned as an assistant prompt message.

ctx must already carry a chatmodel.ChatContext.

func (*Assistant[O]) Description

func (a *Assistant[O]) Description() string

Description returns the description of the Agent, to be used in the prompt of other Agents or LLMs. Should not exceed LLM model limit.

func (*Assistant[O]) FormatPrompt

func (a *Assistant[O]) FormatPrompt(promptInputs map[string]any) (llms.PromptValue, error)

FormatPrompt renders the system prompt template with the configured prompt input merged with the supplied values, where the supplied values win.

func (*Assistant[O]) GetCallConfig added in v0.11.64

func (a *Assistant[O]) GetCallConfig(opts ...Option) *Config

GetCallConfig returns a new Config with the options applied.

func (*Assistant[O]) GetPromptInputVariables

func (a *Assistant[O]) GetPromptInputVariables() []string

GetPromptInputVariables returns the variable names the system prompt requires. Every one must be supplied, because templates are rendered with missingkey=error.

func (*Assistant[O]) GetSkills added in v0.17.130

func (a *Assistant[O]) GetSkills() skills.Skills

GetSkills returns the skills attached with WithSkills.

func (*Assistant[O]) GetSystemPrompt added in v0.2.10

func (a *Assistant[O]) GetSystemPrompt(ctx context.Context, input string, promptInputs map[string]any) (string, error)

GetSystemPrompt generates the system prompt for the Assistant.

func (*Assistant[O]) GetTools added in v0.3.18

func (a *Assistant[O]) GetTools() []tools.ITool

GetTools returns the tools registered with the assistant, in registration order.

func (*Assistant[O]) Name

func (a *Assistant[O]) Name() string

Name returns the name of the Agent.

func (*Assistant[O]) RegisterMCP added in v0.3.11

func (a *Assistant[O]) RegisterMCP(registrator McpServerRegistrator) error

RegisterMCP registers the assistant as an MCP prompt named Name(), taking a chatmodel.MCPInputRequest and answering via CallMCP.

func (*Assistant[O]) Run

func (a *Assistant[O]) Run(ctx context.Context, input *CallInput, optionalOutputType *O) (*Response, error)

Run executes the assistant: it assembles the system prompt, resolves a model when none is configured, then repeatedly calls the LLM and executes the tools it requests until no tool is called. When optionalOutputType is non-nil the final content is parsed into it; passing nil skips parsing, which is what prose assistants want.

ctx must carry a chatmodel.ChatContext, otherwise chatmodel.ErrInvalidChatContext is returned. A response that fails to parse into O is retried once, with the same tools: the retry continues the failed attempt's conversation (question, tool exchanges and unparsable answer) with a request for JSON, and its Response.Messages include the failed attempt's messages. input is not modified. Exceeding MaxToolCalls, MaxMessages or the content-size limit fails the run.

func (*Assistant[O]) WithDescription

func (a *Assistant[O]) WithDescription(description string) *Assistant[O]

WithDescription sets the description of the Agent, to be used in the prompt of other Agents or LLMs.

func (*Assistant[O]) WithInputParser added in v0.3.12

func (a *Assistant[O]) WithInputParser(inputParser func(string) (string, error))

WithInputParser sets the input parser for the Assistant.

func (*Assistant[O]) WithName

func (a *Assistant[O]) WithName(name string) *Assistant[O]

WithName sets the name of the Agent, when used in a prompt of another Agents or LLMs.

func (*Assistant[O]) WithOutputParser

func (a *Assistant[O]) WithOutputParser(outputParser chatmodel.OutputParser[O]) *Assistant[O]

WithCallback sets the callback.

func (*Assistant[O]) WithPromptInputProvider added in v0.3.12

func (a *Assistant[O]) WithPromptInputProvider(cb ProvidePromptInputsFunc)

WithPromptInputProvider registers a callback that computes additional prompt values from the input on every run, merged over the static ones.

func (*Assistant[O]) WithSkills added in v0.16.122

func (a *Assistant[O]) WithSkills(skillsList skills.Skills) *Assistant[O]

WithSkills integrates Agent Skills support (https://agentskills.io) into the assistant. It injects a compact catalog of all loaded skills into the system prompt, and registers the activate_skill tool so the model can load full skill instructions on demand.

No-op if loader is nil or has no loaded skills.

func (*Assistant[O]) WithSkillsPromptProvider added in v0.17.130

func (a *Assistant[O]) WithSkillsPromptProvider(cb ProvideSkillsPromptFunc) *Assistant[O]

WithSkillsPromptProvider replaces DefaultPromptProvider for rendering the skills catalog into the system prompt. Because the catalog is rendered once and cached, call this before the first run.

func (*Assistant[O]) WithTools

func (a *Assistant[O]) WithTools(list ...tools.ITool) *Assistant[O]

WithTools adds new tools to the Assistant, existing tools are not replaced.

type AssistantTool added in v0.3.14

type AssistantTool[I chatmodel.ContentProvider, O chatmodel.ContentProvider] struct {
	// contains filtered or unexported fields
}

AssistantTool adapts a TypeableAssistant to the tools.ITool contract, so one assistant can delegate to another. I is the input type the calling model must produce and defines the tool's JSON schema; O is the wrapped assistant's output type.

func (*AssistantTool[I, O]) Call added in v0.3.14

func (t *AssistantTool[I, O]) Call(ctx context.Context, input string) (string, error)

Call implements tools.ITool by delegating to CallAssistant and discarding the usage stats.

func (*AssistantTool[I, O]) CallAssistant added in v0.3.14

func (t *AssistantTool[I, O]) CallAssistant(ctx context.Context, input string, options ...Option) (string, *llms.UsageStats, error)

CallAssistant parses the raw arguments into I, runs the wrapped assistant and returns the stringified result together with the usage stats, which the calling assistant adds to its own.

Malformed arguments yield chatmodel.ErrFailedUnmarshalInput, which the calling assistant turns into a request to the model to fix its JSON. If the run fails and O implements chatmodel.IBaseResult, the error is recorded as a clarification on the result instead of being returned, so the calling model can recover.

func (*AssistantTool[I, O]) Description added in v0.3.14

func (t *AssistantTool[I, O]) Description() string

Description returns the tool description, defaulting to the wrapped assistant's description.

func (*AssistantTool[I, O]) Name added in v0.3.14

func (t *AssistantTool[I, O]) Name() string

Name returns the tool name, defaulting to the wrapped assistant's name.

func (*AssistantTool[I, O]) Parameters added in v0.3.14

func (t *AssistantTool[I, O]) Parameters() *jsonschema.Schema

Parameters returns the JSON schema derived from the input type I.

func (*AssistantTool[I, O]) RegisterMCP added in v0.3.14

func (t *AssistantTool[I, O]) RegisterMCP(registrator tools.McpServerRegistrator) error

RegisterMCP registers the wrapped assistant as an MCP tool.

func (*AssistantTool[I, O]) RunMCP added in v0.3.14

func (t *AssistantTool[I, O]) RunMCP(ctx context.Context, req *I) (*mcp.ToolResponse, error)

RunMCP handles an MCP tool call by running the wrapped assistant and returning its content as text.

func (*AssistantTool[I, O]) WithDescription added in v0.3.14

func (a *AssistantTool[I, O]) WithDescription(description string) *AssistantTool[I, O]

WithDescription sets the description of the tool, to be used in the prompt of other Agents or LLMs.

func (*AssistantTool[I, O]) WithName added in v0.3.14

func (a *AssistantTool[I, O]) WithName(name string) *AssistantTool[I, O]

WithName sets the name of the tool, when used in a prompt of another Agents or LLMs.

type CallInput added in v0.8.43

type CallInput struct {
	// Input is the input to the assistant.
	Input string
	// PromptInputs is prompt inputs to be rendered in the system prompt.
	PromptInputs map[string]any
	// Options is additional options to be passed to the assistant on run.
	Options []Option
	// Messages is additional content to be sent to the LLM.
	Messages []llms.Message
	// Args is additional arguments to be passed to the assistant on run.
	// This can be used by assistants that implement IAssistant and have a custom implementation of Run.
	Args map[string]string

	// OnProgress is the progress callback, that can be used to report generic progress,
	// in addition to the callback provided in the Options.
	OnProgress OnProgressFunc
}

CallInput is the per-call input to an assistant: the user turn plus optional prompt values, config overrides, extra messages and progress reporting.

func (*CallInput) GetArg added in v0.17.135

func (c *CallInput) GetArg(key string) string

GetArg returns the argument with the given key.

type Callback

type Callback interface {
	tools.Callback
	OnAssistantStart(ctx context.Context, a IAssistant, input string)
	OnAssistantEnd(ctx context.Context, a IAssistant, input string, resp *Response, messageHistory llms.Messages)
	OnAssistantError(ctx context.Context, a IAssistant, input string, err error, messageHistory llms.Messages)
	OnAssistantLLMCallStart(ctx context.Context, a IAssistant, llm llms.Model, payload llms.Messages)
	OnAssistantLLMCallEnd(ctx context.Context, a IAssistant, llm llms.Model, resp *llms.ContentResponse)
	OnAssistantLLMParseError(ctx context.Context, a IAssistant, input string, response string, err error)
	OnToolNotFound(ctx context.Context, a IAssistant, tool string)
}

Callback receives every assistant, LLM and tool event of a run. The handler is propagated into nested assistants invoked through AssistantTool, and tool events are delivered from parallel goroutines, so implementations must be safe for concurrent use. See the callbacks package for implementations.

type Config

type Config struct {
	// Model is the model to use in an LLM call.
	Model     llms.Model
	ModelName string

	// OnModelOptions is a function to be called to modify the options for the model.
	OnModelOptions func(model llms.Model) []Option

	// MaxTokens is the maximum number of tokens to generate to use in an LLM call.
	MaxTokens int

	// Temperature is the temperature for sampling to use in an LLM call, between 0 and 1.
	Temperature float64

	// StopWords is a list of words to stop on to use in an LLM call.
	StopWords []string

	// TopK is the number of tokens to consider for top-k sampling in an LLM call.
	TopK int

	// TopP is the cumulative probability for top-p sampling in an LLM call.
	TopP float64

	// Seed is a seed for deterministic sampling in an LLM call.
	Seed int

	// MinLength is the minimum length of the generated text in an LLM call.
	MinLength int

	// MaxLength is the maximum length of the generated text in an LLM call.
	MaxLength int

	// RepetitionPenalty is the repetition penalty for sampling in an LLM call.
	RepetitionPenalty float64

	// CallbackHandler is the callback handler for Chain
	CallbackHandler Callback

	// Tools is a list of tools to use. Each tool can be a specific tool or a function.
	Tools []llms.Tool

	// ToolChoice is the choice of tool to use, it can either be "none", "auto" (the default behavior), or a specific tool as described in the ToolChoice type.
	ToolChoice any

	// ResponseFormat is a custom response format.
	// If it's not set the response MIME type is text/plain.
	// Otherwise, from response format the JSON mode is derived.
	ResponseFormat *schema.ResponseFormat

	// StreamingFunc is a function to be called for each chunk of a streaming response.
	// Return an error to stop streaming early.
	StreamingFunc func(ctx context.Context, chunk []byte) error

	Store       store.MessageStore
	PromptInput map[string]any
	Examples    chatmodel.FewShotExamples
	// Mode is the encoding mode to use.
	// If ModeJSON then JSON schema instructions are added to the system prompt.
	// If ModeJSONSchema or ModeJSONSchemaStrict and the Model supports it,
	// then the response format is set to json_object.
	Mode encoding.Mode
	// SkipMessageHistory is a flag to skip adding Assistant messages to History.
	SkipMessageHistory bool
	// SkipToolHistory is a flag to skip adding Tool messages to History.
	SkipToolHistory bool
	// IsGeneric is a flag to indicate that the assistant should add a generic message to the history,
	// instead of the human
	IsGeneric bool
	// EnableFunctionCalls is a flag to indicate that the assistant should enable legacy function calls.
	EnableFunctionCalls bool
	// MaxToolCalls is the maximum number of tool calls per run.
	MaxToolCalls int
	// MaxMessages is the maximum number of messages per run.
	MaxMessages int

	// ReasoningEffort is the reasoning effort requested for the run.
	// ReasoningEffortDefault leaves the choice to the effort configured for
	// the model, or to the provider when none is configured.
	ReasoningEffort llms.ReasoningEffort

	// PromptCachePolicy configures provider-native prompt caching for the underlying llm call.
	PromptCachePolicy *llms.PromptCachePolicy
	// contains filtered or unexported fields
}

Config holds an assistant's settings: the model and its call parameters, the tool set, the output mode and the history behavior. It is copied per call by Apply, so per-call options never leak into subsequent calls.

func NewConfig

func NewConfig(opts ...Option) *Config

NewConfig returns a Config with the default mode and limits, then applies the given options.

func (*Config) AddTool added in v0.19.141

func (c *Config) AddTool(tool llms.Tool)

AddTool appends a provider-native tool definition, ignoring duplicates keyed by type and function name.

func (*Config) Apply added in v0.3.12

func (c *Config) Apply(opts ...Option) *Config

Apply applies the options to the new Config.

func (*Config) GetCallOptions

func (cfg *Config) GetCallOptions(options ...Option) []llms.CallOption

GetCallOptions translates the config into provider call options. Only values that were explicitly set are forwarded, so an unset temperature is not sent as zero. Tools the provider does not support, such as web search, are dropped.

type Description added in v0.17.134

type Description struct {
	Name        string              `json:"Name" yaml:"Name"`
	Description string              `json:"Description" yaml:"Description"`
	Tools       []tools.Description `json:"Tools,omitempty" yaml:"Tools,omitempty"`
}

Description is a compact, prompt-friendly summary of an assistant, optionally including its tools. Use it to tell a supervising assistant what specialists are available.

type Descriptions added in v0.17.134

type Descriptions []Description

Descriptions is a renderable collection of assistant descriptions.

func GetDescriptions

func GetDescriptions(list ...IAssistant) Descriptions

GetDescriptions returns the name and description of each assistant, without their tools.

func GetDescriptionsWithTools added in v0.3.18

func GetDescriptionsWithTools(list ...IAssistant) Descriptions

GetDescriptionsWithTools returns the name and description of each assistant together with its tools, for prompts where the tool set informs the routing decision.

func (Descriptions) Render added in v0.17.134

func (d Descriptions) Render(format llmutils.RenderFormat) string

Render renders the descriptions in the requested format; markdown uses ToMarkdown, other formats delegate to llmutils.RenderToString.

func (Descriptions) ToMarkdown added in v0.17.134

func (d Descriptions) ToMarkdown() string

ToMarkdown renders the descriptions as a markdown list, with each description collapsed to a single line.

type IAssistant

type IAssistant interface {
	// Name returns the name of the Assistant.
	Name() string
	// Description returns the description of the Assistant, to be used in the prompt of other Assistants or LLMs.
	// Should not exceed LLM model limit.
	Description() string
	// GetTools returns the tools that the Assistant can use.
	GetTools() []tools.ITool
	// GetSkills returns the skills that the Assistant can activate.
	GetSkills() skills.Skills

	// FormatPrompt renders the Assistant's system prompt with the given values.
	FormatPrompt(values map[string]any) (llms.PromptValue, error)
	// GetPromptInputVariables returns the input variables for the prompt.
	GetPromptInputVariables() []string

	// Call executes the assistant with the given input and prompt inputs.
	// If the assistant fails to parse the input, it should return ErrFailedUnmarshalInput error.
	Call(ctx context.Context, input *CallInput) (*Response, error)
}

IAssistant is the interface every assistant implements. It is what tools, callbacks and orchestrating assistants depend on, so a hand-written flow can be substituted for *Assistant anywhere.

type IAssistantTool added in v0.3.13

type IAssistantTool interface {
	tools.ITool
	// CallAssistant allows the tool to call the assistant with the given input and options.
	// If the assistant fails to parse the input, it should return ErrFailedUnmarshalInput error.
	CallAssistant(ctx context.Context, input string, options ...Option) (string, *llms.UsageStats, error)
}

IAssistantTool provides an interface for tools that use underlying the Assistants.

type IMCPAssistant added in v0.3.11

type IMCPAssistant interface {
	IAssistant
	RegisterMCP(registrator McpServerRegistrator) error
	CallMCP(context.Context, chatmodel.MCPInputRequest) (*mcp.PromptResponse, error)
}

IMCPAssistant is an interface that extends IAssistant to include functionality for registering the assistant with an MCP server. The RegisterMCP method allows the assistant to be registered with a given MCP Server.

type McpServerRegistrator added in v0.3.11

type McpServerRegistrator interface {
	RegisterPrompt(name string, description string, handler any) error
}

McpServerRegistrator registers assistant prompts with an MCP server.

type OnProgressFunc added in v0.13.81

type OnProgressFunc func(ctx context.Context, a IAssistant, title, message string)

OnProgressFunc is a callback for reporting generic progress updates.

type Option

type Option func(*Config)

Option is a function that can be used to modify the behavior of the Agent Config.

func WithCallback

func WithCallback(callbackHandler Callback) Option

WithCallback allows setting a custom Callback Handler.

func WithEnableFunctionCalls added in v0.7.35

func WithEnableFunctionCalls(val bool) Option

WithEnableFunctionCalls is an option to indicate that the assistant should enable legacy function calls.

func WithExamples

func WithExamples(examples chatmodel.FewShotExamples) Option

WithExamples is an option that allows to specify the few-shot examples for the system prompt.

func WithGeneric added in v0.3.12

func WithGeneric(val bool) Option

WithGeneric is an option to indicate that the assistant should add a generic message to the history, instead of the human

func WithMaxLength

func WithMaxLength(maxLength int) Option

WithMaxLength will add an option to set the maximum length of the generated text for LLM.Call.

func WithMaxMessages added in v0.7.42

func WithMaxMessages(maxMessages int) Option

WithMaxMessages caps the total messages per run, including history; exceeding it fails the run. Defaults to DefaultMaxMessages.

func WithMaxTokens

func WithMaxTokens(maxTokens int) Option

WithMaxTokens is an option for LLM.Call.

func WithMaxToolCalls added in v0.7.42

func WithMaxToolCalls(maxToolCalls int) Option

WithMaxToolCalls caps the total tool calls per run; exceeding it fails the run. Defaults to DefaultMaxToolCalls.

func WithMessageStore added in v0.3.12

func WithMessageStore(store store.MessageStore) Option

WithMessageStore is an option that allows to specify the message store.

func WithMinLength

func WithMinLength(minLength int) Option

WithMinLength will add an option to set the minimum length of the generated text for LLM.Call.

func WithMode

func WithMode(mode encoding.Mode) Option

WithMode is an option that allows to specify the encoding mode.

func WithModel

func WithModel(model llms.Model) Option

WithModel is an option for LLM.Call.

func WithModelOptions added in v0.19.141

func WithModelOptions(onModelOptions func(model llms.Model) []Option) Option

WithModelOptions registers a callback that derives extra options from the resolved model, for settings that depend on which provider was selected.

func WithPromptCachePolicy added in v0.15.112

func WithPromptCachePolicy(promptCachePolicy *llms.PromptCachePolicy) Option

WithPromptCachePolicy configures provider-native prompt caching for the underlying llm call.

func WithPromptInput

func WithPromptInput(input map[string]any) Option

WithPromptInput is an option that allows the user to specify the system prompt input.

func WithReasoningEffort added in v0.14.105

func WithReasoningEffort(effort llms.ReasoningEffort) Option

WithReasoningEffort sets the reasoning effort for the run. It overrides the effort configured for the model in the LLM factory, stays below the provider's max_effort, and is sent as the nearest level the model accepts.

func WithRepetitionPenalty

func WithRepetitionPenalty(repetitionPenalty float64) Option

WithRepetitionPenalty will add an option to set the repetition penalty for sampling.

func WithResponseFormat added in v0.10.55

func WithResponseFormat(responseFormat *schema.ResponseFormat) Option

WithResponseFormat overrides the response format derived from the output type and the provider's capabilities.

func WithSeed

func WithSeed(seed int) Option

WithSeed will add an option to use deterministic sampling for LLM.Call.

func WithSkipMessageHistory added in v0.1.7

func WithSkipMessageHistory(skip bool) Option

WithSkipMessageHistory is an option that allows to skip adding Assistant messages to History.

func WithSkipToolHistory added in v0.11.64

func WithSkipToolHistory(skip bool) Option

WithSkipToolHistory is an option that allows to skip adding Tool messages to History.

func WithStopWords

func WithStopWords(stopWords []string) Option

WithStopWords is an option for setting the stop words for LLM.Call.

func WithStreamingFunc

func WithStreamingFunc(streamingFunc func(ctx context.Context, chunk []byte) error) Option

WithStreamingFunc is an option for LLM.Call that allows streaming responses.

func WithTemperature

func WithTemperature(temperature float64) Option

WithTemperature is an option for LLM.Call.

func WithToolChoice

func WithToolChoice(choice any) Option

WithToolChoice is an option for LLM.Call.

func WithTools

func WithTools(tools ...llms.Tool) Option

WithTools is an option for LLM.Call.

func WithTopK

func WithTopK(topK int) Option

WithTopK will add an option to use top-k sampling for LLM.Call.

func WithTopP

func WithTopP(topP float64) Option

WithTopP will add an option to use top-p sampling for LLM.Call.

type ProvidePromptInputsFunc added in v0.3.12

type ProvidePromptInputsFunc func(ctx context.Context, input string) (map[string]any, error)

ProvidePromptInputsFunc is a function that provides prompt inputs for the assistant.

type ProvideSkillsPromptFunc added in v0.17.130

type ProvideSkillsPromptFunc func(ctx context.Context, skillList skills.Skills) (string, error)

ProvideSkillsPromptFunc is a function that provides a prompt for the skills.

type Response added in v0.18.136

type Response struct {
	// Choices is the choices returned by the GenerateContent call.
	Choices []*llms.ContentChoice
	// Messages is the messages that are created from the run and added to the Message History Store.
	Messages []llms.Message
	// Model is the model that was used to generate the response.
	Model string
	// Usage is the usage stats for the response.
	Usage llms.UsageStats
}

Response is the response returned by the assistant.

func NewResponse added in v0.18.136

func NewResponse(val any) *Response

NewResponse builds a Response with a single choice holding the stringified value. Useful for assistants that implement IAssistant themselves.

func (*Response) GetUsage added in v0.19.147

func (c *Response) GetUsage() *llms.UsageStats

GetUsage returns the usage stats, or nil for a nil Response. Safe to call on the result of a failed call.

func (*Response) String added in v0.18.136

func (r *Response) String() string

String returns the response content, joining multiple choices with a blank line.

type TypeableAssistant

type TypeableAssistant[O chatmodel.ContentProvider] interface {
	IAssistant
	// Run executes the assistant with the given input and prompt inputs.
	// If the assistant fails to parse the input, it should return ErrFailedUnmarshalInput error.
	Run(ctx context.Context, input *CallInput, optionalOutputType *O) (*Response, error)
}

TypeableAssistant is an IAssistant with a known output type. Run populates the supplied output value; passing nil skips output parsing entirely.

type TypeableAssistantTool added in v0.3.14

type TypeableAssistantTool[I any, O any] interface {
	IAssistantTool
	tools.IMCPTool
	CallAssistant(ctx context.Context, input string, options ...Option) (string, *llms.UsageStats, error)
}

TypeableAssistantTool is an assistant exposed as a tool, callable both locally by another assistant and remotely over MCP.

func NewAssistantTool added in v0.3.14

NewAssistantTool wraps an assistant as a tool. The tool's name and description default to the assistant's, so naming the assistant well is what makes delegation work; override them by type-asserting the result to *AssistantTool and calling WithName / WithDescription.

O is inferred from the assistant, so only I is normally specified:

tool, err := assistants.NewAssistantTool[chatmodel.InputRequest](researcher)

Jump to

Keyboard shortcuts

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