Documentation
¶
Index ¶
- Constants
- type Agent
- func (a *Agent) Close() error
- func (a *Agent) ExportGraph() (compose.AnyGraph, []compose.GraphAddNodeOpt)
- func (a *Agent) Generate(ctx context.Context, input []*schema.Message, opts ...compose.Option) (*schema.Message, error)
- func (a *Agent) GenerateWithLoop(ctx context.Context, messages []*schema.Message, onToolCall ToolCallHandler, ...) (*schema.Message, error)
- func (a *Agent) GetTools() []tool.BaseTool
- func (a *Agent) Stream(ctx context.Context, input []*schema.Message, opts ...compose.Option) (output *schema.StreamReader[*schema.Message], err error)
- type AgentConfig
- type MessageModifier
- type ResponseHandler
- type ToolCallContentHandler
- type ToolCallHandler
- type ToolResultHandler
Constants ¶
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) 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, onToolResult ToolResultHandler, onResponse ResponseHandler, onToolCallContent ToolCallContentHandler) (*schema.Message, error)
GenerateWithLoop processes messages with a custom loop that displays tool calls in real-time
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
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 ToolResultHandler ¶ added in v0.10.0
ToolResultHandler is a function type for handling tool results