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

messageworkflow

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package messageworkflow provides helpers for workflow executors that buffer incoming messages and act when a turn token arrives, used by the agent-hosting and group-chat executors in workflow/agentworkflow.

Package messageworkflow extends a workflow executor with chat-message handling behavior, accumulating the messages received during a turn and invoking a caller-supplied handler when a turn token arrives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure(executor *workflow.Executor, options *Options)

Configure extends executor with chat-message workflow behavior.

func ConfigureForwarding

func ConfigureForwarding(executor *workflow.Executor, options *ForwardingOptions)

ConfigureForwarding extends executor with forwarding behavior for messages and turn tokens. The configured executor accepts *message.Message, []*message.Message, iter.Seq[*message.Message], and workflow.TurnToken. If options.StringMessageRole is set, it also accepts string and forwards it as a single text message with that role.

Types

type ForwardingOptions

type ForwardingOptions struct {
	// StringMessageRole, when set, enables string input and forwards each
	// string as a [message.Message] with this role.
	StringMessageRole message.Role
}

ForwardingOptions configures ConfigureForwarding.

type MessageState

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

MessageState is the checkpoint-restorable accumulator for a turn's messages. It wraps a StatefulExecutorCache holding the slice of messages received so far.

func NewMessageState

func NewMessageState(stateKey string, scopeName string) *MessageState

NewMessageState returns a MessageState whose accumulated messages are keyed by stateKey within the given scopeName.

func (*MessageState) ProcessTurnMessages

func (s *MessageState) ProcessTurnMessages(ctx *workflow.Context, fn func(ctx *workflow.Context, messages []*message.Message) ([]*message.Message, error)) error

ProcessTurnMessages transforms the accumulated turn messages by invoking fn via InvokeWithState, which reads the current state, calls fn, and queues the returned slice as the new accumulated state.

func (*MessageState) Reset

func (s *MessageState) Reset() error

Reset clears the accumulated turn state. It is registered both as the executor's reset function and as its checkpoint-restored callback.

type Options

type Options struct {
	// StateKey identifies the accumulated turn state within the workflow.
	StateKey string
	// TakeTurnHandler is invoked with the accumulated messages when a turn token arrives.
	TakeTurnHandler func(ctx *workflow.Context, token workflow.TurnToken, messages []*message.Message) error

	// StringMessageRole, when set, registers a handler that wraps incoming
	// string messages with this role.
	StringMessageRole message.Role
	// ScopeName scopes the accumulated turn state; used when constructing a default MessageState.
	ScopeName string
	// AutoSendTurnToken controls whether the turn token is automatically declared
	// and forwarded. The default is true.
	AutoSendTurnToken *bool
	// MessageState supplies an existing accumulator; when nil a new one is created from StateKey and ScopeName.
	MessageState *MessageState
}

Options configures the chat-message workflow behavior applied by Configure. StateKey and TakeTurnHandler are required; Configure panics if options is nil, StateKey is empty, or TakeTurnHandler is nil. The remaining fields are optional.

Jump to

Keyboard shortcuts

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