Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildAgentCallback ¶
func BuildAgentCallback(modelHandler *template.ModelCallbackHandler, toolHandler *template.ToolCallbackHandler) callbacks.Handler
BuildAgentCallback builds a callback handler for agent. e.g.
callback := BuildAgentCallback(modelHandler, toolHandler)
agent, err := react.NewAgent(ctx, &AgentConfig{})
agent.Generate(ctx, input, agent.WithComposeOptions(compose.WithCallbacks(callback)))
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent is the react agent. React agent is a simple agent that handles user messages with a chat model and tools. react will call the chat model, if the message contains tool calls, it will call the tools. if the tool is configured to return directly, react will return directly. otherwise, react will continue to call the chat model until the message contains no tool calls. eg.
agent, err := react.NewAgent(ctx, &react.AgentConfig{})
if err != nil {...}
msg, err := agent.Generate(ctx, []*schema.Message{{Role: schema.User, Content: "how to build agent with eino"}})
if err != nil {...}
println(msg.Content)
func NewAgent ¶
func NewAgent(ctx context.Context, config *AgentConfig) (*Agent, error)
NewAgent creates a react agent.
type AgentConfig ¶
type AgentConfig struct {
// Model is the chat model to be used for handling user messages.
Model model.ChatModel
// ToolsConfig is the config for tools node.
ToolsConfig compose.ToolsNodeConfig
// 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
// MaxStep.
// default 12 of steps in pregel (node num + 10).
MaxStep int `json:"max_step"`
// Tools that will make agent return directly when the tool is called.
ToolReturnDirectly map[string]struct{}
}
AgentConfig is the config for react agent.
type MessageModifier ¶
MessageModifier modify the input messages before the model is called.
func NewPersonaModifier ¶
func NewPersonaModifier(persona string) MessageModifier
NewPersonaModifier add the system prompt as persona before the model is called. example:
persona := "You are an expert in golang."
config := AgentConfig{
Model: model,
MessageModifier: NewPersonaModifier(persona),
}
agent, err := NewAgent(ctx, config)
if err != nil {return}
msg, err := agent.Generate(ctx, []*schema.Message{{Role: schema.User, Content: "how to build agent with eino"}})
if err != nil {return}
println(msg.Content)