agent

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GraphName     = "Agent"
	ModelNodeName = "ChatModel"
	ToolsNodeName = "Tools"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent added in v0.10.0

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

Agent is the agent with real-time tool call display.

func NewAgent added in v0.10.0

func NewAgent(ctx context.Context, config *AgentConfig) (*Agent, error)

NewAgent creates an agent with MCP tool integration and real-time tool call display

func (*Agent) Close added in v0.10.0

func (a *Agent) Close() error

Close closes the agent and cleans up resources

func (*Agent) ExportGraph added in v0.10.0

func (a *Agent) ExportGraph() (compose.AnyGraph, []compose.GraphAddNodeOpt)

ExportGraph exports the underlying graph from Agent, along with the []compose.GraphAddNodeOpt to be used when adding this graph to another graph.

func (*Agent) Generate added in v0.10.0

func (a *Agent) Generate(ctx context.Context, input []*schema.Message, opts ...compose.Option) (*schema.Message, error)

Generate generates a response from the agent.

func (*Agent) GenerateWithLoop added in v0.10.0

func (a *Agent) GenerateWithLoop(ctx context.Context, messages []*schema.Message,
	onToolCall ToolCallHandler, onToolExecution ToolExecutionHandler, onToolResult ToolResultHandler, onResponse ResponseHandler, onToolCallContent ToolCallContentHandler) (*schema.Message, error)

GenerateWithLoop processes messages with a custom loop that displays tool calls in real-time

func (*Agent) GetTools added in v0.10.0

func (a *Agent) GetTools() []tool.BaseTool

GetTools returns the list of available tools

func (*Agent) Stream added in v0.10.0

func (a *Agent) Stream(ctx context.Context, input []*schema.Message, opts ...compose.Option) (output *schema.StreamReader[*schema.Message], err error)

Stream calls the agent and returns a stream response.

type AgentConfig added in v0.10.0

type AgentConfig struct {
	ModelConfig   *models.ProviderConfig
	MCPConfig     *config.Config
	SystemPrompt  string
	MaxSteps      int
	MessageWindow int

	// MessageModifier.
	// modify the input messages before the model is called, it's useful when you want to add some system prompt or other messages.
	MessageModifier MessageModifier

	// Tools that will make agent return directly when the tool is called.
	// When multiple tools are called and more than one tool is in the return directly list, only the first one will be returned.
	ToolReturnDirectly map[string]struct{}

	// StreamOutputHandler is a function to determine whether the model's streaming output contains tool calls.
	StreamToolCallChecker func(ctx context.Context, modelOutput *schema.StreamReader[*schema.Message]) (bool, error)
}

AgentConfig is the config for agent.

type MessageModifier added in v0.10.0

type MessageModifier func(ctx context.Context, input []*schema.Message) []*schema.Message

MessageModifier modify the input messages before the model is called.

type ResponseHandler added in v0.10.0

type ResponseHandler func(content string)

ResponseHandler is a function type for handling LLM responses

type ToolCallContentHandler added in v0.10.0

type ToolCallContentHandler func(content string)

ToolCallContentHandler is a function type for handling content that accompanies tool calls

type ToolCallHandler added in v0.10.0

type ToolCallHandler func(toolName, toolArgs string)

ToolCallHandler is a function type for handling tool calls as they happen

type ToolExecutionHandler added in v0.11.0

type ToolExecutionHandler func(toolName string, isStarting bool)

ToolExecutionHandler is a function type for handling tool execution start/end

type ToolResultHandler added in v0.10.0

type ToolResultHandler func(toolName, toolArgs, result string, isError bool)

ToolResultHandler is a function type for handling tool results

Jump to

Keyboard shortcuts

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