Documentation
¶
Overview ¶
Package protocol defines collaboration protocol interfaces and registry.
Protocols are the heart of Meanwhile—they define how agents collaborate. Think of protocols as meeting styles: brainstorming sessions, debates, consensus-building, delegation handoffs, or breakout groups.
Built-in protocols:
- Solo - Single-agent execution (default)
- Handoff - Simple delegation from one agent to another
- Brainstorming - Diverge, interact, and vote like a real brainstorm
- Adversarial - Debate with opposing positions
- Consensus - Convergent collaboration to agreement
- Breakout - Parallel group work with synthesis
- Caucus - Private per-participant prep
All protocols support functional options for customization:
proto := protocol.Brainstorming(
protocol.WithBrainstormingConcurrency(3),
)
Protocols can be wrapped as tools via engine.AsTool() for nested collaboration.
Meanwhile... protocols orchestrate, agents collaborate, and work gets done.
Index ¶
- func DecodeState(state map[string]any, out any) error
- func EncodeState(state any) (map[string]any, error)
- func PromptWithMedia(text string, source agent.Message) agent.Message
- type AdversarialOption
- type AwaitingInputError
- type BrainstormingOption
- func WithBrainstormingBriefs(briefs ...string) BrainstormingOption
- func WithBrainstormingConcurrency(maxConcurrent int) BrainstormingOption
- func WithBrainstormingContextMessageBuilder(builder ContextMessageBuilder) BrainstormingOption
- func WithBrainstormingDisableInterjections() BrainstormingOption
- func WithBrainstormingDivergentPrompt(builder DivergentPromptBuilder) BrainstormingOption
- func WithBrainstormingDivergentRounds(rounds int) BrainstormingOption
- func WithBrainstormingIdeaTarget(count int) BrainstormingOption
- func WithBrainstormingInteractionPrompt(builder InteractionPromptBuilder) BrainstormingOption
- func WithBrainstormingInteractionRounds(rounds int) BrainstormingOption
- func WithBrainstormingModeratorClosing(builder ModeratorClosingBuilder) BrainstormingOption
- func WithBrainstormingModeratorInterjection(builder ModeratorInterjectionBuilder) BrainstormingOption
- func WithBrainstormingModeratorInterventions(points ...float64) BrainstormingOption
- func WithBrainstormingModeratorOpening(builder ModeratorOpeningBuilder) BrainstormingOption
- func WithBrainstormingModeratorShortlist(builder ModeratorShortlistBuilder) BrainstormingOption
- func WithBrainstormingModeratorSynthesis(builder ModeratorSynthesisBuilder) BrainstormingOption
- func WithBrainstormingOutcome(outcome string) BrainstormingOption
- func WithBrainstormingParams(params map[string]any) BrainstormingOption
- func WithBrainstormingScope(scope string) BrainstormingOption
- func WithBrainstormingScopeFallback(fallback ScopeFallback) BrainstormingOption
- func WithBrainstormingScopeRefinementPrompt(prompt ScopeRefinementPrompt) BrainstormingOption
- func WithBrainstormingShortlistSize(count int) BrainstormingOption
- func WithBrainstormingVotePrompt(builder VotePromptBuilder) BrainstormingOption
- func WithBrainstormingVoteWeights(weights ...int) BrainstormingOption
- func WithBrainstormingVotesPerAgent(count int) BrainstormingOption
- func WithBrainstormingVoting(enabled bool) BrainstormingOption
- type BreakoutOption
- type Config
- type ConfigProvider
- type ContextConfig
- type ContextMessageBuilder
- type DivergentPromptBuilder
- type DivergentPromptInput
- type Factory
- type InputOption
- type InputOptions
- type InputRequest
- type InteractionPromptBuilder
- type InteractionPromptInput
- type ModeratorClosingBuilder
- type ModeratorClosingInput
- type ModeratorInterjectionBuilder
- type ModeratorInterjectionInput
- type ModeratorOpeningBuilder
- type ModeratorOpeningInput
- type ModeratorPrompt
- type ModeratorShortlistBuilder
- type ModeratorShortlistInput
- type ModeratorSynthesisBuilder
- type ModeratorSynthesisInput
- type Participant
- type Protocol
- type Registry
- type ResultProvider
- type RunRequest
- type ScopeFallback
- type ScopeRefinementPrompt
- type Session
- type StatefulProtocol
- type SummarizationConfig
- type TimeoutProvider
- type TurnOption
- type TurnOptions
- type TurnResume
- type VoteBallot
- type VotePromptBuilder
- type VotePromptInput
- type VoteTally
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeState ¶
DecodeState restores structured state from a serialized map.
func EncodeState ¶
EncodeState converts a structured state into a serializable map.
Types ¶
type AdversarialOption ¶
type AdversarialOption func(*adversarialConfig)
AdversarialOption configures adversarial behavior.
func WithDebatePrefixes ¶
func WithDebatePrefixes(proPrefix, conPrefix string) AdversarialOption
WithDebatePrefixes sets prompt prefixes for pro and con arguments.
func WithDebateSynthesis ¶
func WithDebateSynthesis(fn func(topic, pro, con string) string) AdversarialOption
WithDebateSynthesis overrides the synthesis prompt builder.
type AwaitingInputError ¶
type AwaitingInputError struct {
Request InputRequest
}
AwaitingInputError signals that execution paused for human input.
func (*AwaitingInputError) Error ¶
func (e *AwaitingInputError) Error() string
type BrainstormingOption ¶
type BrainstormingOption func(*brainstormingConfig)
BrainstormingOption configures brainstorming behavior.
func WithBrainstormingBriefs ¶
func WithBrainstormingBriefs(briefs ...string) BrainstormingOption
WithBrainstormingBriefs adds brief context snippets.
func WithBrainstormingConcurrency ¶
func WithBrainstormingConcurrency(maxConcurrent int) BrainstormingOption
WithBrainstormingConcurrency limits concurrent agent runs.
func WithBrainstormingContextMessageBuilder ¶
func WithBrainstormingContextMessageBuilder(builder ContextMessageBuilder) BrainstormingOption
WithBrainstormingContextMessageBuilder sets the context message builder.
func WithBrainstormingDisableInterjections ¶
func WithBrainstormingDisableInterjections() BrainstormingOption
WithBrainstormingDisableInterjections turns off moderator interjections.
func WithBrainstormingDivergentPrompt ¶
func WithBrainstormingDivergentPrompt(builder DivergentPromptBuilder) BrainstormingOption
WithBrainstormingDivergentPrompt sets the divergent prompt builder.
func WithBrainstormingDivergentRounds ¶
func WithBrainstormingDivergentRounds(rounds int) BrainstormingOption
WithBrainstormingDivergentRounds sets the number of private divergent rounds.
func WithBrainstormingIdeaTarget ¶
func WithBrainstormingIdeaTarget(count int) BrainstormingOption
WithBrainstormingIdeaTarget sets the number of ideas per participant in divergence.
func WithBrainstormingInteractionPrompt ¶
func WithBrainstormingInteractionPrompt(builder InteractionPromptBuilder) BrainstormingOption
WithBrainstormingInteractionPrompt sets the interaction prompt builder.
func WithBrainstormingInteractionRounds ¶
func WithBrainstormingInteractionRounds(rounds int) BrainstormingOption
WithBrainstormingInteractionRounds sets the number of interactive discussion rounds. Use 0 to skip interaction entirely.
func WithBrainstormingModeratorClosing ¶
func WithBrainstormingModeratorClosing(builder ModeratorClosingBuilder) BrainstormingOption
WithBrainstormingModeratorClosing sets the moderator closing prompt builder.
func WithBrainstormingModeratorInterjection ¶
func WithBrainstormingModeratorInterjection(builder ModeratorInterjectionBuilder) BrainstormingOption
WithBrainstormingModeratorInterjection sets the moderator interjection prompt builder.
func WithBrainstormingModeratorInterventions ¶
func WithBrainstormingModeratorInterventions(points ...float64) BrainstormingOption
WithBrainstormingModeratorInterventions sets moderator intervention points.
func WithBrainstormingModeratorOpening ¶
func WithBrainstormingModeratorOpening(builder ModeratorOpeningBuilder) BrainstormingOption
WithBrainstormingModeratorOpening sets the moderator opening prompt builder.
func WithBrainstormingModeratorShortlist ¶
func WithBrainstormingModeratorShortlist(builder ModeratorShortlistBuilder) BrainstormingOption
WithBrainstormingModeratorShortlist sets the moderator shortlist prompt builder.
func WithBrainstormingModeratorSynthesis ¶
func WithBrainstormingModeratorSynthesis(builder ModeratorSynthesisBuilder) BrainstormingOption
WithBrainstormingModeratorSynthesis sets the moderator synthesis prompt builder.
func WithBrainstormingOutcome ¶
func WithBrainstormingOutcome(outcome string) BrainstormingOption
WithBrainstormingOutcome sets the intended outcome.
func WithBrainstormingParams ¶
func WithBrainstormingParams(params map[string]any) BrainstormingOption
WithBrainstormingParams sets default run parameters for agent turns (e.g., temperature). Any params explicitly set on an agent will take precedence.
func WithBrainstormingScope ¶
func WithBrainstormingScope(scope string) BrainstormingOption
WithBrainstormingScope sets the brainstorming scope description.
func WithBrainstormingScopeFallback ¶
func WithBrainstormingScopeFallback(fallback ScopeFallback) BrainstormingOption
WithBrainstormingScopeFallback sets the fallback scope builder.
func WithBrainstormingScopeRefinementPrompt ¶
func WithBrainstormingScopeRefinementPrompt(prompt ScopeRefinementPrompt) BrainstormingOption
WithBrainstormingScopeRefinementPrompt sets the scope refinement prompt builder.
func WithBrainstormingShortlistSize ¶
func WithBrainstormingShortlistSize(count int) BrainstormingOption
WithBrainstormingShortlistSize sets the number of ideas to shortlist.
func WithBrainstormingVotePrompt ¶
func WithBrainstormingVotePrompt(builder VotePromptBuilder) BrainstormingOption
WithBrainstormingVotePrompt sets the vote prompt builder.
func WithBrainstormingVoteWeights ¶
func WithBrainstormingVoteWeights(weights ...int) BrainstormingOption
WithBrainstormingVoteWeights sets the weighting for ranked votes.
func WithBrainstormingVotesPerAgent ¶
func WithBrainstormingVotesPerAgent(count int) BrainstormingOption
WithBrainstormingVotesPerAgent sets the number of votes per participant.
func WithBrainstormingVoting ¶
func WithBrainstormingVoting(enabled bool) BrainstormingOption
WithBrainstormingVoting enables or disables voting.
type BreakoutOption ¶
type BreakoutOption func(*breakoutConfig)
BreakoutOption configures breakout behavior.
func WithBreakoutGroupSize ¶
func WithBreakoutGroupSize(size int) BreakoutOption
WithBreakoutGroupSize sets the group size for automatic splits.
func WithBreakoutGroups ¶
func WithBreakoutGroups(groups map[string][]agent.Agent) BreakoutOption
WithBreakoutGroups sets explicit breakout groups.
type ConfigProvider ¶
type ConfigProvider interface {
Config() Config
}
ConfigProvider exposes protocol configuration for persistence.
type ContextConfig ¶
type ContextConfig struct {
MaxPromptTokens int `json:"max_prompt_tokens" yaml:"max_prompt_tokens"`
RollingWindow int `json:"rolling_window" yaml:"rolling_window"`
MaxToolOutputChars int `json:"max_tool_output_chars" yaml:"max_tool_output_chars"`
Summarization SummarizationConfig `json:"summarization" yaml:"summarization"`
}
ContextConfig configures context selection.
type ContextMessageBuilder ¶
ContextMessageBuilder builds a context message for participants.
type DivergentPromptBuilder ¶
type DivergentPromptBuilder func(input DivergentPromptInput) string
DivergentPromptBuilder builds a participant system prompt for divergent ideation.
type DivergentPromptInput ¶
type DivergentPromptInput struct {
BasePrompt string
Scope string
Round int
MaxRounds int
IdeaTarget int
}
DivergentPromptInput provides context for divergent prompts.
type InputOption ¶
type InputOption func(*InputOptions)
InputOption mutates InputOptions.
func WithInputDeadline ¶
func WithInputDeadline(deadline time.Time) InputOption
WithInputDeadline sets an absolute timeout deadline for a human input request.
func WithInputTimeout ¶
func WithInputTimeout(timeout time.Duration) InputOption
WithInputTimeout sets a relative timeout for a human input request.
type InputOptions ¶
InputOptions configure a human input request.
type InputRequest ¶
type InputRequest struct {
RequestID string
ParticipantID string
ParticipantName string
Context string
RequestedAt time.Time
TimeoutAt time.Time
}
InputRequest captures a pending human input request.
func (InputRequest) TimedOut ¶
func (r InputRequest) TimedOut(now time.Time) bool
TimedOut reports whether the request has timed out.
func (InputRequest) TimeoutRemaining ¶
TimeoutRemaining reports the remaining time until timeout, if configured.
type InteractionPromptBuilder ¶
type InteractionPromptBuilder func(input InteractionPromptInput) string
InteractionPromptBuilder builds a participant system prompt for interactive discussion.
type InteractionPromptInput ¶
type InteractionPromptInput struct {
BasePrompt string
Scope string
Board string
Round int
MaxRounds int
TurnIndex int
Speakers int
Move string
}
InteractionPromptInput provides context for interaction prompts.
type ModeratorClosingBuilder ¶
type ModeratorClosingBuilder func(input ModeratorClosingInput) ModeratorPrompt
ModeratorClosingBuilder builds a moderator closing prompt.
type ModeratorClosingInput ¶
type ModeratorClosingInput struct {
Scope string
Board string
Shortlist []string
Tally []VoteTally
}
ModeratorClosingInput provides context for the closing summary.
type ModeratorInterjectionBuilder ¶
type ModeratorInterjectionBuilder func(input ModeratorInterjectionInput) ModeratorPrompt
ModeratorInterjectionBuilder builds a moderator interjection prompt.
type ModeratorInterjectionInput ¶
type ModeratorInterjectionInput struct {
Scope string
Board string
Progress float64
CurrentRound int
MaxRounds int
Recent []string
}
ModeratorInterjectionInput provides context for interjections.
type ModeratorOpeningBuilder ¶
type ModeratorOpeningBuilder func(input ModeratorOpeningInput) ModeratorPrompt
ModeratorOpeningBuilder builds a moderator opening prompt.
type ModeratorOpeningInput ¶
ModeratorOpeningInput provides context for the opening message.
type ModeratorPrompt ¶
ModeratorPrompt defines input for moderator runs.
type ModeratorShortlistBuilder ¶
type ModeratorShortlistBuilder func(input ModeratorShortlistInput) ModeratorPrompt
ModeratorShortlistBuilder builds a moderator shortlist prompt.
type ModeratorShortlistInput ¶
ModeratorShortlistInput provides context for shortlist building.
type ModeratorSynthesisBuilder ¶
type ModeratorSynthesisBuilder func(input ModeratorSynthesisInput) ModeratorPrompt
ModeratorSynthesisBuilder builds a moderator synthesis prompt.
type ModeratorSynthesisInput ¶
ModeratorSynthesisInput provides context for idea synthesis.
type Participant ¶
type Participant interface {
Identifier() string
DisplayName() string
IsHuman() bool
IsAgent() bool
Agent() (agent.Agent, bool)
}
Participant represents a session participant (agent or human).
type Protocol ¶
type Protocol interface {
ID() string
Participants() []Participant
Init(ctx context.Context, sess Session) error
OnMessage(ctx context.Context, sess Session, msg agent.Message) error
OnEvent(ctx context.Context, sess Session, ev event.Event) error
Shutdown(ctx context.Context, sess Session) error
}
Protocol defines collaboration behavior for a session.
func Adversarial ¶
func Adversarial(opts ...AdversarialOption) Protocol
Adversarial creates an adversarial debate protocol where two agents take opposing positions with optional facilitator synthesis.
func Brainstorming ¶
func Brainstorming(opts ...BrainstormingOption) Protocol
Brainstorming creates a brainstorming protocol with divergent ideation, interactive discussion, and optional voting.
func Breakout ¶
func Breakout(opts ...BreakoutOption) Protocol
Breakout creates a breakout-reconvene protocol where participants split into sub-groups, work in parallel, then reconvene for synthesis.
func Debate ¶
func Debate(opts ...AdversarialOption) Protocol
Debate is a friendly alias for Adversarial. Creates a debate protocol where two agents take opposing positions.
func Handoff ¶
func Handoff(caller, callee Participant) Protocol
Handoff creates a handoff protocol that delegates work from one agent to another.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores protocol factories.
type ResultProvider ¶
ResultProvider exposes structured results for a protocol run.
type RunRequest ¶
type RunRequest struct {
Messages []agent.Message
SystemMessages []agent.Message
Params map[string]any
MaxToolIterations int
MaxRunDuration time.Duration
Tools []string // Tool IDs to add for this run
ToolPolicy tool.Policy
Context ContextConfig
OutputSchema any // Optional: constrains output to this type (overrides agent-level schema)
Silent bool
}
RunRequest configures an agent execution.
type ScopeFallback ¶
ScopeFallback builds a scope message when refinement is not configured.
type ScopeRefinementPrompt ¶
type ScopeRefinementPrompt func(userQuestion, configuredScope string) (systemPrompt, userPrompt string)
ScopeRefinementPrompt builds system + user prompts for scope refinement.
type Session ¶
type Session interface {
ID() string
Name() string
Tags() []string
Metadata() map[string]any
ProtocolID() string
Participants() []Participant
Facilitator() *agent.Agent
Groups() map[string][]Participant
Emit(event.Event) error
EmitWithContext(ctx context.Context, ev event.Event) error
RunAgent(ctx context.Context, agent agent.Agent, req RunRequest) (agent.Message, error)
RunTurn(ctx context.Context, participant Participant, req RunRequest, opts ...TurnOption) (agent.Message, error)
AwaitInput(ctx context.Context, participant Participant, turnContext string, resume TurnResume, opts ...InputOption) error
// Tool registration for session-scoped tools
RegisterTool(t any) error
RegisterTools(tools ...any) error
AddDefaultTools(ids ...string)
DefaultTools() []string
}
Session exposes minimal session capabilities to protocols.
type StatefulProtocol ¶
type StatefulProtocol interface {
Protocol
GetState() (map[string]any, error)
SetState(state map[string]any) error
}
StatefulProtocol exposes protocol state for checkpointing.
type SummarizationConfig ¶
type SummarizationConfig struct {
Enabled bool `json:"enabled" yaml:"enabled"`
ThresholdTokens int `json:"threshold_tokens" yaml:"threshold_tokens"`
}
SummarizationConfig controls summary behavior.
type TimeoutProvider ¶
TimeoutProvider supplies a default timeout for session runs.
type TurnOption ¶
type TurnOption func(*TurnOptions)
TurnOption mutates TurnOptions.
func WithTurnContext ¶
func WithTurnContext(context string) TurnOption
WithTurnContext provides context shown to a human during their turn.
func WithTurnDeadline ¶
func WithTurnDeadline(deadline time.Time) TurnOption
WithTurnDeadline sets an absolute timeout deadline for a human turn.
func WithTurnResume ¶
func WithTurnResume(resume TurnResume) TurnOption
WithTurnResume sets the callback that resumes the protocol after human input.
func WithTurnTimeout ¶
func WithTurnTimeout(timeout time.Duration) TurnOption
WithTurnTimeout sets a relative timeout for a human turn.
type TurnOptions ¶
type TurnOptions struct {
Context string
Resume TurnResume
Timeout time.Duration
Deadline time.Time
}
TurnOptions configure a participant turn.
type TurnResume ¶
TurnResume resumes a paused human turn with the provided response.
type VoteBallot ¶
type VoteBallot struct {
Agent string `json:"agent"`
Picks []string `json:"picks"`
Rationale string `json:"rationale,omitempty"`
Raw string `json:"raw,omitempty"`
}
VoteBallot captures a participant's vote.
type VotePromptBuilder ¶
type VotePromptBuilder func(input VotePromptInput) string
VotePromptBuilder builds a participant vote prompt.
type VotePromptInput ¶
VotePromptInput provides context for vote prompts.