Documentation
¶
Index ¶
- Constants
- Variables
- func AddSessionValue(ctx context.Context, key string, value any)
- func AddSessionValues(ctx context.Context, kvs map[string]any)
- func ClearRunCtx(ctx context.Context) context.Context
- func GenTransferMessages(_ context.Context, destAgentName string) (Message, Message)
- func GetImplSpecificOptions[T any](base *T, opts ...AgentRunOption) *T
- func GetMessage(e *AgentEvent) (Message, *AgentEvent, error)
- func GetSessionValue(ctx context.Context, key string) (any, bool)
- func GetSessionValues(ctx context.Context) map[string]any
- func NewAgentTool(_ context.Context, agent Agent, options ...AgentToolOption) tool.BaseTool
- func NewAsyncIteratorPair[T any]() (*AsyncIterator[T], *AsyncGenerator[T])
- func SendToolGenAction(ctx context.Context, toolName string, action *AgentAction) error
- type Agent
- func AgentWithDeterministicTransferTo(_ context.Context, config *DeterministicTransferConfig) Agent
- func AgentWithOptions(ctx context.Context, agent Agent, opts ...AgentOption) Agent
- func NewLoopAgent(ctx context.Context, config *LoopAgentConfig) (Agent, error)
- func NewParallelAgent(ctx context.Context, config *ParallelAgentConfig) (Agent, error)
- func NewSequentialAgent(ctx context.Context, config *SequentialAgentConfig) (Agent, error)
- func SetSubAgents(ctx context.Context, agent Agent, subAgents []Agent) (Agent, error)
- type AgentAction
- type AgentEvent
- type AgentInput
- type AgentOption
- type AgentOutput
- type AgentRunOption
- func WithAgentToolRunOptions(opts map[string][]AgentRunOption) AgentRunOption
- func WithChatModelOptions(opts []model.Option) AgentRunOption
- func WithCheckPointID(id string) AgentRunOption
- func WithHistoryModifier(f func(context.Context, []Message) []Message) AgentRunOption
- func WithSessionValues(v map[string]any) AgentRunOption
- func WithSkipTransferMessages() AgentRunOption
- func WithToolOptions(opts []tool.Option) AgentRunOption
- func WrapImplSpecificOptFn[T any](optFn func(*T)) AgentRunOption
- type AgentToolOption
- type AgentToolOptions
- type AsyncGenerator
- type AsyncIterator
- type BreakLoopAction
- type ChatModelAgent
- func (a *ChatModelAgent) Description(_ context.Context) string
- func (a *ChatModelAgent) Name(_ context.Context) string
- func (a *ChatModelAgent) OnDisallowTransferToParent(_ context.Context) error
- func (a *ChatModelAgent) OnSetAsSubAgent(_ context.Context, parent Agent) error
- func (a *ChatModelAgent) OnSetSubAgents(_ context.Context, subAgents []Agent) error
- func (a *ChatModelAgent) Resume(ctx context.Context, info *ResumeInfo, opts ...AgentRunOption) *AsyncIterator[*AgentEvent]
- func (a *ChatModelAgent) Run(ctx context.Context, input *AgentInput, opts ...AgentRunOption) *AsyncIterator[*AgentEvent]
- type ChatModelAgentConfig
- type ChatModelAgentInterruptInfo
- type DeterministicTransferConfig
- type ExitTool
- type GenModelInput
- type HistoryEntry
- type HistoryRewriter
- type InterruptInfo
- type LoopAgentConfig
- type Message
- type MessageStream
- type MessageVariant
- type OnSubAgents
- type ParallelAgentConfig
- type ResumableAgent
- type ResumeInfo
- type RunStep
- type Runner
- func (r *Runner) Query(ctx context.Context, query string, opts ...AgentRunOption) *AsyncIterator[*AgentEvent]
- func (r *Runner) Resume(ctx context.Context, checkPointID string, opts ...AgentRunOption) (*AsyncIterator[*AgentEvent], error)
- func (r *Runner) Run(ctx context.Context, messages []Message, opts ...AgentRunOption) *AsyncIterator[*AgentEvent]
- type RunnerConfig
- type SequentialAgentConfig
- type State
- type ToolsConfig
- type TransferToAgentAction
- type WorkflowInterruptInfo
Constants ¶
const ( TransferToAgentToolName = "transfer_to_agent" TransferToAgentToolDesc = "Transfer the question to another agent." )
const (
TransferToAgentInstruction = `` /* 268-byte string literal not displayed */
)
Variables ¶
var ErrExceedMaxIterations = errors.New("exceeds max iterations")
var ( ToolInfoExit = &schema.ToolInfo{ Name: "exit", Desc: "Exit the agent process and return the final result.", ParamsOneOf: schema.NewParamsOneOfByParams(map[string]*schema.ParameterInfo{ "final_result": { Desc: "the final result to return", Required: true, Type: schema.String, }, }), } )
Functions ¶
func ClearRunCtx ¶
ClearRunCtx clears the run context of the multi-agents. This is particularly useful when a customized agent with a multi-agents inside it is set as a subagent of another multi-agents. In such cases, it's not expected to pass the outside run context to the inside multi-agents, so this function helps isolate the contexts properly.
func GenTransferMessages ¶
func GetImplSpecificOptions ¶
func GetImplSpecificOptions[T any](base *T, opts ...AgentRunOption) *T
GetImplSpecificOptions extract the implementation specific options from AgentRunOption list, optionally providing a base options with default values. e.g.
myOption := &MyOption{
Field1: "default_value",
}
myOption := model.GetImplSpecificOptions(myOption, opts...)
func GetMessage ¶
func GetMessage(e *AgentEvent) (Message, *AgentEvent, error)
func NewAgentTool ¶
func NewAsyncIteratorPair ¶
func NewAsyncIteratorPair[T any]() (*AsyncIterator[T], *AsyncGenerator[T])
func SendToolGenAction ¶
func SendToolGenAction(ctx context.Context, toolName string, action *AgentAction) error
Types ¶
type Agent ¶
type Agent interface {
Name(ctx context.Context) string
Description(ctx context.Context) string
// Run runs the agent.
// The returned AgentEvent within the AsyncIterator must be safe to modify.
// If the returned AgentEvent within the AsyncIterator contains MessageStream,
// the MessageStream MUST be exclusive and safe to be received directly.
// NOTE: it's recommended to use SetAutomaticClose() on the MessageStream of AgentEvents emitted by AsyncIterator,
// so that even the events are not processed, the MessageStream can still be closed.
Run(ctx context.Context, input *AgentInput, options ...AgentRunOption) *AsyncIterator[*AgentEvent]
}
func AgentWithDeterministicTransferTo ¶
func AgentWithDeterministicTransferTo(_ context.Context, config *DeterministicTransferConfig) Agent
func AgentWithOptions ¶
func AgentWithOptions(ctx context.Context, agent Agent, opts ...AgentOption) Agent
func NewLoopAgent ¶
func NewLoopAgent(ctx context.Context, config *LoopAgentConfig) (Agent, error)
func NewParallelAgent ¶
func NewParallelAgent(ctx context.Context, config *ParallelAgentConfig) (Agent, error)
func NewSequentialAgent ¶
func NewSequentialAgent(ctx context.Context, config *SequentialAgentConfig) (Agent, error)
type AgentAction ¶
type AgentAction struct {
Exit bool
Interrupted *InterruptInfo
TransferToAgent *TransferToAgentAction
BreakLoop *BreakLoopAction
CustomizedAction any
}
func NewBreakLoopAction ¶ added in v0.5.8
func NewBreakLoopAction(agentName string) *AgentAction
NewBreakLoopAction creates a new BreakLoopAction, signaling a request to terminate the current loop.
func NewExitAction ¶
func NewExitAction() *AgentAction
func NewTransferToAgentAction ¶
func NewTransferToAgentAction(destAgentName string) *AgentAction
type AgentEvent ¶
type AgentEvent struct {
AgentName string
RunPath []RunStep
Output *AgentOutput
Action *AgentAction
Err error
}
func EventFromMessage ¶
func EventFromMessage(msg Message, msgStream MessageStream, role schema.RoleType, toolName string) *AgentEvent
type AgentInput ¶
type AgentOption ¶
type AgentOption func(options *flowAgent)
func WithDisallowTransferToParent ¶
func WithDisallowTransferToParent() AgentOption
func WithHistoryRewriter ¶
func WithHistoryRewriter(h HistoryRewriter) AgentOption
type AgentOutput ¶
type AgentOutput struct {
MessageOutput *MessageVariant
CustomizedOutput any
}
type AgentRunOption ¶
type AgentRunOption struct {
// contains filtered or unexported fields
}
AgentRunOption is the call option for adk Agent.
func WithAgentToolRunOptions ¶
func WithAgentToolRunOptions(opts map[string][]AgentRunOption) AgentRunOption
func WithChatModelOptions ¶
func WithChatModelOptions(opts []model.Option) AgentRunOption
func WithCheckPointID ¶
func WithCheckPointID(id string) AgentRunOption
func WithHistoryModifier ¶
func WithHistoryModifier(f func(context.Context, []Message) []Message) AgentRunOption
func WithSessionValues ¶
func WithSessionValues(v map[string]any) AgentRunOption
func WithSkipTransferMessages ¶
func WithSkipTransferMessages() AgentRunOption
func WithToolOptions ¶
func WithToolOptions(opts []tool.Option) AgentRunOption
func WrapImplSpecificOptFn ¶
func WrapImplSpecificOptFn[T any](optFn func(*T)) AgentRunOption
WrapImplSpecificOptFn is the option to wrap the implementation specific option function.
func (AgentRunOption) DesignateAgent ¶
func (o AgentRunOption) DesignateAgent(name ...string) AgentRunOption
type AgentToolOption ¶
type AgentToolOption func(*AgentToolOptions)
func WithAgentInputSchema ¶ added in v0.5.4
func WithAgentInputSchema(schema *schema.ParamsOneOf) AgentToolOption
func WithFullChatHistoryAsInput ¶
func WithFullChatHistoryAsInput() AgentToolOption
type AgentToolOptions ¶
type AgentToolOptions struct {
// contains filtered or unexported fields
}
type AsyncGenerator ¶
type AsyncGenerator[T any] struct { // contains filtered or unexported fields }
func (*AsyncGenerator[T]) Close ¶
func (ag *AsyncGenerator[T]) Close()
func (*AsyncGenerator[T]) Send ¶
func (ag *AsyncGenerator[T]) Send(v T)
type AsyncIterator ¶
type AsyncIterator[T any] struct { // contains filtered or unexported fields }
func (*AsyncIterator[T]) Next ¶
func (ai *AsyncIterator[T]) Next() (T, bool)
type BreakLoopAction ¶ added in v0.5.8
type BreakLoopAction struct {
// From records the name of the agent that initiated the break loop action.
From string
// Done is a state flag that can be used by the framework to mark when the
// action has been handled.
Done bool
// CurrentIterations is populated by the framework to record at which
// iteration the loop was broken.
CurrentIterations int
}
BreakLoopAction is a programmatic-only agent action used to prematurely terminate the execution of a loop workflow agent. When a loop workflow agent receives this action from a sub-agent, it will stop its current iteration and will not proceed to the next one. It will mark the BreakLoopAction as Done, signalling to any 'upper level' loop agent that this action has been processed and should be ignored further up. This action is not intended to be used by LLMs.
type ChatModelAgent ¶
type ChatModelAgent struct {
// contains filtered or unexported fields
}
func NewChatModelAgent ¶
func NewChatModelAgent(_ context.Context, config *ChatModelAgentConfig) (*ChatModelAgent, error)
func (*ChatModelAgent) Description ¶
func (a *ChatModelAgent) Description(_ context.Context) string
func (*ChatModelAgent) OnDisallowTransferToParent ¶
func (a *ChatModelAgent) OnDisallowTransferToParent(_ context.Context) error
func (*ChatModelAgent) OnSetAsSubAgent ¶
func (a *ChatModelAgent) OnSetAsSubAgent(_ context.Context, parent Agent) error
func (*ChatModelAgent) OnSetSubAgents ¶
func (a *ChatModelAgent) OnSetSubAgents(_ context.Context, subAgents []Agent) error
func (*ChatModelAgent) Resume ¶
func (a *ChatModelAgent) Resume(ctx context.Context, info *ResumeInfo, opts ...AgentRunOption) *AsyncIterator[*AgentEvent]
func (*ChatModelAgent) Run ¶
func (a *ChatModelAgent) Run(ctx context.Context, input *AgentInput, opts ...AgentRunOption) *AsyncIterator[*AgentEvent]
type ChatModelAgentConfig ¶
type ChatModelAgentConfig struct {
// Name of the agent. Better be unique across all agents.
Name string
// Description of the agent's capabilities.
// Helps other agents determine whether to transfer tasks to this agent.
Description string
// Instruction used as the system prompt for this agent.
// Optional. If empty, no system prompt will be used.
// Supports f-string placeholders for session values in default GenModelInput, for example:
// "You are a helpful assistant. The current time is {Time}. The current user is {User}."
// These placeholders will be replaced with session values for "Time" and "User".
Instruction string
Model model.ToolCallingChatModel
ToolsConfig ToolsConfig
// GenModelInput transforms instructions and input messages into the model's input format.
// Optional. Defaults to defaultGenModelInput which combines instruction and messages.
GenModelInput GenModelInput
// Exit defines the tool used to terminate the agent process.
// Optional. If nil, no Exit Action will be generated.
// You can use the provided 'ExitTool' implementation directly.
Exit tool.BaseTool
// OutputKey stores the agent's response in the session.
// Optional. When set, stores output via AddSessionValue(ctx, outputKey, msg.Content).
OutputKey string
// MaxIterations defines the upper limit of ChatModel generation cycles.
// The agent will terminate with an error if this limit is exceeded.
// Optional. Defaults to 20.
MaxIterations int
}
type ChatModelAgentInterruptInfo ¶
type ChatModelAgentInterruptInfo struct {
Info *compose.InterruptInfo
Data []byte
}
type GenModelInput ¶
type GenModelInput func(ctx context.Context, instruction string, input *AgentInput) ([]Message, error)
GenModelInput transforms agent instructions and input into a format suitable for the model.
type HistoryEntry ¶
type HistoryRewriter ¶
type HistoryRewriter func(ctx context.Context, entries []*HistoryEntry) ([]Message, error)
type InterruptInfo ¶
type InterruptInfo struct {
Data any
}
type LoopAgentConfig ¶
type MessageStream ¶
type MessageStream = *schema.StreamReader[Message]
type MessageVariant ¶
type MessageVariant struct {
IsStreaming bool
Message Message
MessageStream MessageStream
// message role: Assistant or Tool
Role schema.RoleType
// only used when Role is Tool
ToolName string
}
func (*MessageVariant) GetMessage ¶
func (mv *MessageVariant) GetMessage() (Message, error)
func (*MessageVariant) GobDecode ¶
func (mv *MessageVariant) GobDecode(b []byte) error
func (*MessageVariant) GobEncode ¶
func (mv *MessageVariant) GobEncode() ([]byte, error)
type OnSubAgents ¶
type ParallelAgentConfig ¶
type ResumableAgent ¶
type ResumableAgent interface {
Agent
Resume(ctx context.Context, info *ResumeInfo, opts ...AgentRunOption) *AsyncIterator[*AgentEvent]
}
type ResumeInfo ¶
type ResumeInfo struct {
EnableStreaming bool
*InterruptInfo
}
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
func (*Runner) Query ¶
func (r *Runner) Query(ctx context.Context, query string, opts ...AgentRunOption) *AsyncIterator[*AgentEvent]
func (*Runner) Resume ¶
func (r *Runner) Resume(ctx context.Context, checkPointID string, opts ...AgentRunOption) (*AsyncIterator[*AgentEvent], error)
func (*Runner) Run ¶
func (r *Runner) Run(ctx context.Context, messages []Message, opts ...AgentRunOption) *AsyncIterator[*AgentEvent]
type RunnerConfig ¶
type RunnerConfig struct {
Agent Agent
EnableStreaming bool
CheckPointStore compose.CheckPointStore
}
type SequentialAgentConfig ¶
type ToolsConfig ¶
type ToolsConfig struct {
compose.ToolsNodeConfig
// ReturnDirectly specifies tools that cause the agent to return immediately when called.
// If multiple listed tools are called simultaneously, only the first one triggers the return.
// The map keys are tool names indicate whether the tool should trigger immediate return.
ReturnDirectly map[string]bool
}
type TransferToAgentAction ¶
type TransferToAgentAction struct {
DestAgentName string
}
type WorkflowInterruptInfo ¶
type WorkflowInterruptInfo struct {
OrigInput *AgentInput
SequentialInterruptIndex int
SequentialInterruptInfo *InterruptInfo
LoopIterations int
ParallelInterruptInfo map[int]*InterruptInfo
}