react

package
v0.0.0-...-ca21e7b Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithChatModelOptions

func WithChatModelOptions(opts ...model.Option) base.AgentOption

WithChatModelOptions returns an agent option that specifies model.Option for the chat model in agent.

func WithMessageHandler

func WithMessageHandler(handler MessageHandler) base.AgentOption

WithMessageHandler returns an agent option that specifies the message handler.

func WithToolList

func WithToolList(tools ...tool.BaseTool) base.AgentOption

WithToolList returns an agent option that specifies the list of tools can be called which are BaseTool but must implement InvokableTool or StreamableTool.

func WithToolOptions

func WithToolOptions(opts ...tool.Option) base.AgentOption

WithToolOptions returns an agent option that specifies tool.Option for the tools in agent.

Types

type AgentState

type AgentState struct {
	Messages                 []*schema.Message `json:"messages"`
	ReasoningHistory         []Reasoning       `json:"reasoning_history"`
	Iteration                int               `json:"iteration"`
	MaxIterations            int               `json:"max_iterations"`
	Completed                bool              `json:"completed"`
	FinalAnswer              string            `json:"final_answer"`
	ReturnDirectlyToolCallID string            `json:"return_directly_tool_call_id"`
	// ForceFinalAnswer indicates the next reasoning step must produce a final answer
	// and disallow tool calls or continued thinking.
	ForceFinalAnswer bool `json:"force_final_answer"`
}

AgentState represents the global state of the agent used with Eino's state management

type CompleteHandler

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

func NewCompleteHandler

func NewCompleteHandler(config ReactAgentConfig) *CompleteHandler

func (*CompleteHandler) PostHandler

func (h *CompleteHandler) PostHandler(ctx context.Context, output *schema.Message, state *AgentState) (*schema.Message, error)

type InitHandler

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

func NewInitHandler

func NewInitHandler(config ReactAgentConfig) *InitHandler

func (*InitHandler) PreHandler

func (h *InitHandler) PreHandler(ctx context.Context, input []*schema.Message, state *AgentState) ([]*schema.Message, error)

type MessageHandler

type MessageHandler interface {
	OnMessage(ctx context.Context, message *schema.Message) (context.Context, error)
	OnStreamMessage(ctx context.Context, message *schema.StreamReader[*schema.Message]) (context.Context, error)
}

type MessageModifier

type MessageModifier func([]*schema.Message) []*schema.Message

MessageModifier is a function type for modifying messages

type ReactAgent

type ReactAgent struct {
	Runnable         compose.Runnable[[]*schema.Message, *schema.Message]
	Graph            *compose.Graph[[]*schema.Message, *schema.Message]
	GraphAddNodeOpts []compose.GraphAddNodeOpt
	AgentOptions     []base.AgentOption
	Config           ReactAgentConfig
}

ReactAgent represents the ReAct agent

func NewAgent

func NewAgent(ctx context.Context, config ReactAgentConfig, opts ...base.AgentOption) (*ReactAgent, error)

NewAgent creates a new ReAct agent with the given configuration

func (*ReactAgent) Generate

func (a *ReactAgent) Generate(ctx context.Context, messages []*schema.Message, opts ...base.AgentOption) (*schema.Message, error)

Generate executes the agent with comprehensive error handling and monitoring

func (*ReactAgent) Stream

func (a *ReactAgent) Stream(ctx context.Context, messages []*schema.Message, opts ...base.AgentOption) (*schema.StreamReader[*schema.Message], error)

Stream executes the agent with streaming support and comprehensive monitoring

type ReactAgentConfig

type ReactAgentConfig struct {
	// Model for reasoning and tool calling
	ToolCallingModel model.ToolCallingChatModel

	// ReasoningPrompt is the prompt template for reasoning
	ReasoningPrompt string

	// IsSupportStructuredOutput is whether the model supports structured output
	IsSupportStructuredOutput bool

	// Tools available to the agent
	ToolsConfig compose.ToolsNodeConfig

	// Message modifier for preprocessing
	MessageModifier MessageModifier

	// Maximum number of reasoning iterations
	MaxStep int

	// Enable debug mode
	DebugMode bool

	// Custom graph options
	GraphOptions []compose.GraphAddNodeOpt

	// Tools that should return directly without further reasoning
	// Map of tool name to whether it should return directly
	ToolReturnDirectly map[string]bool
}

ReactAgentConfig is the configuration for the ReAct agent

func DefaultConfig

func DefaultConfig() *ReactAgentConfig

DefaultConfig returns a default agent configuration

type Reasoning

type Reasoning struct {
	Thought     string            `json:"thought"`
	Action      string            `json:"action"`
	ToolCalls   []schema.ToolCall `json:"tool_call,omitempty"`
	FinalAnswer string            `json:"final_answer,omitempty"`
	Confidence  float64           `json:"confidence"`
}

Reasoning represents the result of reasoning process

type ReasoningHandler

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

func NewReasoningHandler

func NewReasoningHandler(config ReactAgentConfig) *ReasoningHandler

func (*ReasoningHandler) PostHandler

func (h *ReasoningHandler) PostHandler(ctx context.Context, output *schema.Message, state *AgentState) (*schema.Message, error)

func (*ReasoningHandler) PreHandler

func (h *ReasoningHandler) PreHandler(ctx context.Context, input []*schema.Message, state *AgentState) ([]*schema.Message, error)

type ReasoningOutput

type ReasoningOutput struct {
	Thought     string  `json:"thought"`
	Action      string  `json:"action"`
	FinalAnswer string  `json:"final_answer"`
	Confidence  float64 `json:"confidence"`
}

ReasoningOutput represents the output of reasoning process

type ToolHandler

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

func NewToolHandler

func NewToolHandler(config ReactAgentConfig) *ToolHandler

func (*ToolHandler) PostHandler

func (h *ToolHandler) PostHandler(ctx context.Context, output []*schema.Message, state *AgentState) ([]*schema.Message, error)

Jump to

Keyboard shortcuts

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