host

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2025 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Overview

Package host implements the host pattern for multi-agent system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithAgentCallbacks

func WithAgentCallbacks(agentCallbacks ...MultiAgentCallback) agent.AgentOption

Types

type AgentMeta

type AgentMeta struct {
	Name        string // the name of the agent, should be unique within multi-agent system
	IntendedUse string // the intended use-case of the agent, used as the reason for the multi-agent system to hand over control to this agent
}

AgentMeta is the meta information of an agent within a multi-agent system.

type HandOffInfo

type HandOffInfo struct {
	ToAgentName string
	Argument    string
}

HandOffInfo is the info which will be passed to MultiAgentCallback.OnHandOff, representing a hand off event.

type Host

type Host struct {
	ChatModel    model.ChatModel
	SystemPrompt string
}

Host is the host agent within a multi-agent system. Currently, it can only be a model.ChatModel.

type MultiAgent

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

MultiAgent is a host multi-agent system. A host agent is responsible for deciding which specialist to 'hand off' the task to. One or more specialist agents are responsible for completing the task.

func NewMultiAgent

func NewMultiAgent(ctx context.Context, config *MultiAgentConfig) (*MultiAgent, error)

NewMultiAgent creates a new host multi-agent system.

IMPORTANT!! For models that don't output tool calls in the first streaming chunk (e.g. Claude) the default StreamToolCallChecker may not work properly since it only checks the first chunk for tool calls. In such cases, you need to implement a custom StreamToolCallChecker that can properly detect tool calls.

func (*MultiAgent) Generate

func (ma *MultiAgent) Generate(ctx context.Context, input []*schema.Message, opts ...agent.AgentOption) (*schema.Message, error)

func (*MultiAgent) Stream

func (ma *MultiAgent) Stream(ctx context.Context, input []*schema.Message, opts ...agent.AgentOption) (*schema.StreamReader[*schema.Message], error)

type MultiAgentCallback

type MultiAgentCallback interface {
	OnHandOff(ctx context.Context, info *HandOffInfo) context.Context
}

MultiAgentCallback is the callback interface for host multi-agent.

type MultiAgentConfig

type MultiAgentConfig struct {
	Host        Host
	Specialists []*Specialist

	Name string // the name of the host multi-agent

	// StreamOutputHandler is a function to determine whether the model's streaming output contains tool calls.
	// Different models have different ways of outputting tool calls in streaming mode:
	// - Some models (like OpenAI) output tool calls directly
	// - Others (like Claude) output text first, then tool calls
	// This handler allows custom logic to check for tool calls in the stream.
	// It should return:
	// - true if the output contains tool calls and agent should continue processing
	// - false if no tool calls and agent should stop
	// Note: This field only needs to be configured when using streaming mode
	// Note: The handler MUST close the modelOutput stream before returning
	// Optional. By default, it checks if the first chunk contains tool calls.
	// Note: The default implementation does not work well with Claude, which typically outputs tool calls after text content.
	StreamToolCallChecker func(ctx context.Context, modelOutput *schema.StreamReader[*schema.Message]) (bool, error)
}

MultiAgentConfig is the config for host multi-agent system.

type Specialist

type Specialist struct {
	AgentMeta

	ChatModel    model.ChatModel
	SystemPrompt string

	Invokable  compose.Invoke[[]*schema.Message, *schema.Message, agent.AgentOption]
	Streamable compose.Stream[[]*schema.Message, *schema.Message, agent.AgentOption]
}

Specialist is a specialist agent within a host multi-agent system. It can be a model.ChatModel or any Invokable and/or Streamable, such as react.Agent. ChatModel and (Invokable / Streamable) are mutually exclusive, only one should be provided. If Invokable is provided but not Streamable, then the Specialist will be compose.InvokableLambda. If Streamable is provided but not Invokable, then the Specialist will be compose.StreamableLambda. if Both Invokable and Streamable is provided, then the Specialist will be compose.AnyLambda.

Jump to

Keyboard shortcuts

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