agenticraft_foundation.mpst.patterns¶
4 communication patterns built from session types: request-response, pipeline, scatter-gather, consensus.
Common multi-agent session patterns.
This module provides reusable session type patterns for common multi-agent communication scenarios.
Patterns: - RequestResponse: Simple client-server request-response - ScatterGather: Coordinator sends to all, gathers responses - Pipeline: Sequential processing through stages - Consensus: Multi-party agreement protocol
Each pattern provides: - Global type constructor - Local type projections - Example usage
ConsensusPattern
dataclass
¶
Two-Phase Commit consensus pattern.
| ATTRIBUTE | DESCRIPTION |
|---|---|
coordinator |
Coordinator participant ID
TYPE:
|
participants |
List of participant IDs
TYPE:
|
prepare_label |
Label for prepare messages
TYPE:
|
vote_yes_label |
Label for affirmative vote
TYPE:
|
vote_no_label |
Label for negative vote
TYPE:
|
commit_label |
Label for commit decision
TYPE:
|
abort_label |
Label for abort decision
TYPE:
|
global_type(with_choice=False)
¶
Build the global session type.
| PARAMETER | DESCRIPTION |
|---|---|
with_choice
|
If True, include explicit choice branches (only practical for 1-2 participants)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SessionType
|
Global type for two-phase commit |
participants_set()
¶
Get all participants including coordinator.
PipelinePattern
dataclass
¶
Pipeline session pattern.
| ATTRIBUTE | DESCRIPTION |
|---|---|
stages |
List of stage participant IDs in order
TYPE:
|
data_label |
Label for data messages between stages
TYPE:
|
repeatable |
If True, pipeline can repeat
TYPE:
|
global_type()
¶
Build the global session type.
| RETURNS | DESCRIPTION |
|---|---|
SessionType
|
Global type for pipeline |
The type is
Stage_1 → Stage_2 : Data. Stage_2 → Stage_3 : Data. ... Stage_{n-1} → Stage_n : Data. end (or X for repeatable)
participants()
¶
Get all participants in the pipeline.
| RETURNS | DESCRIPTION |
|---|---|
set[ParticipantId]
|
Set of stage participant identifiers. |
RequestResponsePattern
dataclass
¶
Request-Response session pattern.
| ATTRIBUTE | DESCRIPTION |
|---|---|
client |
Client participant ID
TYPE:
|
server |
Server participant ID
TYPE:
|
request_label |
Label for request message
TYPE:
|
response_label |
Label for response message
TYPE:
|
repeatable |
If True, pattern can repeat
TYPE:
|
global_type()
¶
Build the global session type.
| RETURNS | DESCRIPTION |
|---|---|
SessionType
|
Global type for request-response |
participants()
¶
Get all participants in the request-response interaction.
| RETURNS | DESCRIPTION |
|---|---|
set[ParticipantId]
|
Set containing the client and server identifiers. |
ScatterGatherPattern
dataclass
¶
Scatter-Gather session pattern.
| ATTRIBUTE | DESCRIPTION |
|---|---|
coordinator |
Coordinator participant ID
TYPE:
|
workers |
List of worker participant IDs
TYPE:
|
task_label |
Label for task messages
TYPE:
|
result_label |
Label for result messages
TYPE:
|
global_type()
¶
Build the global session type.
| RETURNS | DESCRIPTION |
|---|---|
SessionType
|
Global type for scatter-gather |
The type is
Coordinator → Worker_1 : Task. ... Coordinator → Worker_n : Task. Worker_1 → Coordinator : Result. ... Worker_n → Coordinator : Result. end
participants()
¶
Get all participants in the scatter-gather pattern.
| RETURNS | DESCRIPTION |
|---|---|
set[ParticipantId]
|
Set containing the coordinator and all worker identifiers. |
two_phase_commit(coordinator='coordinator', participants=None, with_choice=False)
¶
Create a two-phase commit global type.
| PARAMETER | DESCRIPTION |
|---|---|
coordinator
|
Coordinator participant name
TYPE:
|
participants
|
List of participant names
TYPE:
|
with_choice
|
Include explicit choice branches (only for 1-2 participants)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SessionType
|
Global session type |