Help us shape the future of Go! Take the 2026 Go Developer Survey

agentworkflow

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

This file hosts an agent.Agent as a workflow workflow.Executor, so the agent can participate in graphs alongside regular executors and other hosted agents.

Package agentworkflow bridges agents and workflows.

This file hosts a workflow.Workflow as an agent.Agent.

The first agent run on a session opens a streaming workflow run; subsequent runs reuse it. Workflow events are translated into agent [agent.ResponseUpdate]s as the workflow executes. Pending external requests raised by the workflow (via workflow.RequestInfoEvent) are surfaced as response updates carrying the request content; the caller can then resume by including the matching response content (e.g. message.FunctionResultContent or message.ToolApprovalResponseContent) in the next agent run, and the provider routes them as [workflow.ExternalResponse]s.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

New creates a workflow workflow.ExecutorBinding that hosts the given agent.Agent using the supplied Config. The zero value of Config is a sensible default. New panics if a is nil.

func NewAgent

func NewAgent(wf *workflow.Workflow, cfg AgentConfig) (*agent.Agent, error)

NewAgent wraps a *workflow.Workflow as an *agent.Agent.

The workflow's start executor must accept [[]*message.Message] (typically configured via messageworkflow.Configure). On the first call to the agent's Run for a given session, a fresh streaming run is started. Subsequent calls reuse that run, sending follow-up messages and [workflow.ExternalResponse]s.

Types

type AgentConfig

type AgentConfig struct {
	agent.Config

	// Environment is the execution environment used to run the workflow on
	// each agent turn. When nil, [inproc.Concurrent] is used if every workflow
	// executor supports concurrent shared execution; otherwise [inproc.OffThread]
	// is used.
	Environment *inproc.ExecutionEnvironment

	// IncludeOutputsInResponse, if true, surfaces [workflow.OutputEvent]
	// payloads in the agent response stream when the payload is a
	// [*message.Message], [[]*message.Message], or [*agent.Response]. By
	// default, only [*agent.ResponseUpdate] payloads emitted by hosted agents
	// inside the workflow are surfaced as response content.
	IncludeOutputsInResponse bool

	// IncludeErrorDetails, if true, surfaces the full error message from
	// [workflow.ErrorEvent]s in the agent response stream. When false, a
	// generic message is emitted instead.
	IncludeErrorDetails bool
}

AgentConfig configures a workflow.Workflow hosted as an agent.Agent via NewAgent.

type ConcurrentWorkflowBuilder

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

ConcurrentWorkflowBuilder fluently builds concurrent agent workflows.

func NewConcurrentWorkflowBuilder

func NewConcurrentWorkflowBuilder(agents ...*agent.Agent) *ConcurrentWorkflowBuilder

NewConcurrentWorkflowBuilder creates a builder for a concurrent agent workflow.

func (*ConcurrentWorkflowBuilder) Build

Build builds the concurrent workflow.

func (*ConcurrentWorkflowBuilder) WithAggregator

WithAggregator sets the concurrent output aggregator. Nil keeps the default aggregator.

func (*ConcurrentWorkflowBuilder) WithDescription

func (b *ConcurrentWorkflowBuilder) WithDescription(description string) *ConcurrentWorkflowBuilder

WithDescription sets the workflow description.

func (*ConcurrentWorkflowBuilder) WithIntermediateOutputFrom

func (b *ConcurrentWorkflowBuilder) WithIntermediateOutputFrom(agents ...*agent.Agent) *ConcurrentWorkflowBuilder

WithIntermediateOutputFrom designates agents as intermediate workflow output sources.

func (*ConcurrentWorkflowBuilder) WithName

WithName sets the workflow name.

func (*ConcurrentWorkflowBuilder) WithOutputFrom

func (b *ConcurrentWorkflowBuilder) WithOutputFrom(agents ...*agent.Agent) *ConcurrentWorkflowBuilder

WithOutputFrom designates agents as terminal workflow output sources.

type Config

type Config struct {
	// EmitUpdateEvents controls whether streaming [agent.ResponseUpdate]
	// outputs are emitted as the agent runs. When nil, a [workflow.TurnToken]
	// controls update emission for that turn.
	EmitUpdateEvents *bool

	// EmitResponseEvents controls whether an aggregated [agent.Response]
	// output is emitted at the end of each turn.
	EmitResponseEvents bool

	// ForwardIncomingMessages controls whether incoming messages are forwarded
	// downstream before the agent runs. The default is true.
	ForwardIncomingMessages *bool

	// ReassignOtherAgentsAsUsers controls whether incoming
	// [message.RoleAssistant] messages whose [message.Message.AuthorName]
	// does not match this agent are rewritten to [message.RoleUser]. The default
	// is true.
	ReassignOtherAgentsAsUsers *bool

	// InterceptUserInputRequests controls how [message.ToolApprovalRequestContent]
	// produced by the agent is dispatched.
	//
	// When false (the default), each request is raised as a workflow
	// [workflow.ExternalRequest] via [workflow.Context.PostRequest], and
	// the matching [workflow.ExternalResponse] is delivered back to this
	// executor by the runner.
	//
	// When true, each request is sent as a regular workflow message (via
	// [workflow.Context.SendMessage]) so other executors in the graph can
	// handle the approval; the matching
	// [message.ToolApprovalResponseContent] must be routed back to
	// this executor as a workflow message.
	//
	// In both modes the agent is re-invoked with the response merged into
	// the conversation, and the [workflow.TurnToken] propagated downstream
	// after the turn is held until all outstanding requests are resolved.
	InterceptUserInputRequests bool

	// InterceptUnterminatedFunctionCalls controls how
	// [message.FunctionCallContent] produced by the agent without a
	// matching [message.FunctionResultContent] in the same turn is
	// dispatched.
	//
	// When false (the default), each unresolved call is raised as a
	// workflow [workflow.ExternalRequest] via
	// [workflow.Context.PostRequest], and the matching
	// [workflow.ExternalResponse] is delivered back to this executor by
	// the runner.
	//
	// When true, each unresolved call is sent as a regular workflow
	// message (via [workflow.Context.SendMessage]); the matching
	// [message.FunctionResultContent] must be routed back to this
	// executor as a workflow message.
	//
	// In both modes the agent is re-invoked with the result merged into
	// the conversation, and the [workflow.TurnToken] propagated downstream
	// after the turn is held until all outstanding calls are resolved.
	InterceptUnterminatedFunctionCalls bool
}

Config configures how an agent.Agent is hosted as a workflow workflow.Executor.

type GroupChatManager

type GroupChatManager struct {
	// SelectNextAgent selects the next participant to speak. Returning nil ends
	// the chat and yields the accumulated conversation.
	SelectNextAgent func(ctx context.Context, history []*message.Message) (*agent.Agent, error)

	// UpdateHistory filters the messages broadcast to participants for the current
	// turn. Returning nil preserves the original messages.
	UpdateHistory func(ctx context.Context, messages []*message.Message) ([]*message.Message, error)

	// ShouldTerminate decides whether the chat should end. When nil, the host
	// stops after 40 participant turns.
	ShouldTerminate func(ctx context.Context, history []*message.Message, iterationCount int) (bool, error)

	// Reset clears manager-owned local state when the hosting executor is reset.
	Reset func()

	// OnCheckpoint persists manager-owned state. The supplied context prefixes
	// state keys with "GroupChatManager_" so custom manager state cannot collide
	// with host state.
	OnCheckpoint func(ctx *workflow.Context) error

	// OnCheckpointRestored restores manager-owned state from the same prefixed
	// state context used by OnCheckpoint.
	OnCheckpointRestored func(ctx *workflow.Context) error
}

GroupChatManager manages the flow of a group chat. SelectNextAgent is required; all other functions are optional.

func NewRoundRobinGroupChatManager

func NewRoundRobinGroupChatManager(agents []*agent.Agent, opts RoundRobinGroupChatOptions) *GroupChatManager

NewRoundRobinGroupChatManager creates a GroupChatManager that selects agents in a round-robin order.

type GroupChatManagerFactory

type GroupChatManagerFactory func(agents []*agent.Agent) *GroupChatManager

GroupChatManagerFactory creates the manager used by a group chat workflow run. The returned manager must set GroupChatManager.SelectNextAgent.

type GroupChatWorkflowBuilder

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

GroupChatWorkflowBuilder fluently builds group chat workflows.

func NewGroupChatWorkflowBuilder

func NewGroupChatWorkflowBuilder(managerFactory GroupChatManagerFactory, agents ...*agent.Agent) *GroupChatWorkflowBuilder

NewGroupChatWorkflowBuilder creates a builder for a group chat workflow.

func (*GroupChatWorkflowBuilder) Build

Build builds the group chat workflow.

func (*GroupChatWorkflowBuilder) WithDescription

func (b *GroupChatWorkflowBuilder) WithDescription(description string) *GroupChatWorkflowBuilder

WithDescription sets the workflow description.

func (*GroupChatWorkflowBuilder) WithIntermediateOutputFrom

func (b *GroupChatWorkflowBuilder) WithIntermediateOutputFrom(agents ...*agent.Agent) *GroupChatWorkflowBuilder

WithIntermediateOutputFrom designates agents as intermediate workflow output sources.

func (*GroupChatWorkflowBuilder) WithName

WithName sets the workflow name.

func (*GroupChatWorkflowBuilder) WithOutputFrom

func (b *GroupChatWorkflowBuilder) WithOutputFrom(agents ...*agent.Agent) *GroupChatWorkflowBuilder

WithOutputFrom designates agents as terminal workflow output sources.

type MessageAggregator

type MessageAggregator func(context.Context, [][]*message.Message) []*message.Message

MessageAggregator combines per-agent message batches into a single batch.

type ResetSignal

type ResetSignal struct{}

ResetSignal notifies an agent-hosting executor to reset its agent conversation state and start a new session when appropriate.

type RoundRobinGroupChatOptions

type RoundRobinGroupChatOptions struct {
	// MaximumIterationCount is the maximum number of participant turns before
	// the default termination behavior ends the chat. The zero value is 40.
	MaximumIterationCount int

	// ShouldTerminate can stop the chat before the default iteration-limit check
	// runs.
	ShouldTerminate func(ctx context.Context, history []*message.Message, iterationCount int) (bool, error)
}

RoundRobinGroupChatOptions configures NewRoundRobinGroupChatManager.

type SequentialWorkflowBuilder

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

SequentialWorkflowBuilder fluently builds sequential agent workflows.

func NewSequentialWorkflowBuilder

func NewSequentialWorkflowBuilder(agents ...*agent.Agent) *SequentialWorkflowBuilder

NewSequentialWorkflowBuilder creates a builder for a sequential agent workflow.

func (*SequentialWorkflowBuilder) Build

Build builds the sequential workflow.

func (*SequentialWorkflowBuilder) WithChainOnlyAgentResponses

func (b *SequentialWorkflowBuilder) WithChainOnlyAgentResponses(enabled bool) *SequentialWorkflowBuilder

WithChainOnlyAgentResponses controls whether each agent only forwards its own response to the next agent, instead of forwarding the full accumulated conversation. The default is false.

func (*SequentialWorkflowBuilder) WithDescription

func (b *SequentialWorkflowBuilder) WithDescription(description string) *SequentialWorkflowBuilder

WithDescription sets the workflow description.

func (*SequentialWorkflowBuilder) WithIntermediateOutputFrom

func (b *SequentialWorkflowBuilder) WithIntermediateOutputFrom(agents ...*agent.Agent) *SequentialWorkflowBuilder

WithIntermediateOutputFrom designates agents as intermediate workflow output sources.

func (*SequentialWorkflowBuilder) WithName

WithName sets the workflow name.

func (*SequentialWorkflowBuilder) WithOutputFrom

func (b *SequentialWorkflowBuilder) WithOutputFrom(agents ...*agent.Agent) *SequentialWorkflowBuilder

WithOutputFrom designates agents as terminal workflow output sources.

Jump to

Keyboard shortcuts

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