Communication

class terrarium.core.blackboard.Blackboard(blackboard_id='-1', participants=<factory>, initial_context='', agents=<factory>, logs=<factory>, template=<factory>, verify_template=0, suspended=False)[source]

Bases: object

Append-only event log.

Provides methods for posting, scanning, and creating text summaries for LLM prompting. Each blackboard has a unique ID and tracks its participants.

Parameters:
class terrarium.core.blackboard.Event(id, ts, agent, kind, payload=<factory>, refs=<factory>, blackboard_id=None)[source]

Bases: object

Event object for blackboard communication between agents.

Variables:
  • id (str) – Unique identifier for the event

  • ts (float) – Timestamp when event was created

  • agent (str) – Name of agent that created the event

  • kind (str) – Type of event (proposal, counter-offer, introduction, explanation, etc.)

  • payload (Dict[str, Any]) – Free-form dictionary containing event-specific data

  • refs (List[str]) – List of event IDs this event references

  • blackboard_id (int | None) – ID of the blackboard this event belongs to

Parameters:
class terrarium.core.blackboard.Megaboard[source]

Bases: object

Factor graph-based blackboard system for multi-agent communication.

Maintains multiple blackboards with template verification and factor graph initialization. Designed for structured agent communication and optional external tool integration.

Initialize the Megaboard system.

add_blackboard(agents, template=None)[source]

Add a new blackboard with the specified agents.

Parameters:
  • agents (List[str]) – List of agent names who will participate

  • template (Dict[str, Any] | None) – Optional template for event validation

Returns:

The blackboard ID (index in the list)

Return type:

int

clear_blackboards()[source]

Clear all blackboards. Used when starting a new simulation.

Return type:

None

create_channel(agent_name, participants, message='', phase=None, iteration=None)[source]

Open a private channel between the caller and the given agents.

The channel is a normal blackboard, so only its participants can read or post to it. Reuses an existing private channel with the same membership.

Parameters:
  • agent_name (str)

  • participants (List[str])

  • message (str)

  • phase (str | None)

  • iteration (int | None)

Return type:

Dict[str, Any]

get(blackboard_id, agent, limit=None)[source]

Get recent events from the blackboard for the specified agent.

Parameters:
  • blackboard_id (int) – ID of the blackboard

  • agent (str) – Name of the agent requesting events

  • limit (int | None) – Maximum number of recent events to return

Returns:

List of recent events

Return type:

List[Dict[str, Any]]

get_agent_blackboard_contexts(agent_name)[source]

Get context summaries for all blackboards that an agent participates in. This is used as context in agent prompts.

Parameters:

agent_name (str) – Name of the agent

Returns:

Dictionary mapping string blackboard_id -> context_summary

Return type:

Dict[str, str]

get_agent_blackboards(agent_name)[source]

Get list of blackboard string IDs that an agent participates in.

Parameters:

agent_name (str)

Return type:

List[str]

get_blackboard_by_string_id(blackboard_id)[source]

Get a Blackboard object given a string ID. Returns None if not found or invalid ID.

Parameters:

blackboard_id (str)

Return type:

Blackboard | None

get_blackboard_string_ids()[source]

Get all blackboard IDs as strings.

Returns:

List of string blackboard IDs for all existing non-suspended blackboards

Return type:

List[str]

handle_tool_call(tool_name, agent_name, arguments, phase=None, iteration=None)[source]

Handle blackboard tool calls by routing to appropriate methods.

Parameters:
  • tool_name (str) – Name of the tool to execute

  • agent_name (str) – Name of the agent calling the tool

  • arguments (Dict[str, Any]) – Parameters for the tool call

  • phase (str | None) – Current simulation phase (planning/execution)

  • iteration (int | None) – Current iteration number

Returns:

Dictionary with tool execution result

Return type:

Dict[str, Any]

is_private_channel(blackboard_id)[source]

Whether a blackboard is an agent-created private channel.

Parameters:

blackboard_id (Any)

Return type:

bool

log_action_to_blackboards(agent_name, action, result, phase=None, iteration=None)[source]

Log an action to all blackboards that the agent belongs to.

Parameters:
  • agent_name (str) – Name of the agent performing the action

  • action (Dict[str, Any]) – Dictionary containing action type and parameters

  • result (Dict[str, Any]) – Result from action execution

  • phase (str | None) – Current simulation phase (planning/execution)

  • iteration (int | None) – Current iteration number

Return type:

None

post(blackboard_id, agent, kind, payload=None, phase=None, iteration=None)[source]

Post a new event to the specified blackboard.

Parameters:
  • blackboard_id (int) – ID of the target blackboard

  • agent (str) – Name of the agent posting the event

  • kind (str) – Type of event being posted

  • payload (Dict[str, Any] | None) – Event data and content

  • phase (str | None) – Current simulation phase (planning/execution) - will be stored in payload

  • iteration (int | None) – Current iteration number - will be stored in payload

Returns:

The unique ID of the created event

Return type:

str

post_system_message(blackboard_id, kind, payload=None, phase=None, iteration=None)[source]

Post a system message to the blackboard (bypasses agent membership check).

Parameters:
  • blackboard_id (int) – ID of the blackboard

  • kind (str) – Type of event being posted

  • payload (Dict[str, Any] | None) – Event data and content

  • phase (str | None) – Current simulation phase (planning/execution) - will be stored in payload

  • iteration (int | None) – Current iteration number - will be stored in payload

Returns:

The unique ID of the created event

Return type:

str

recall(blackboard_id, agent, query, limit=5)[source]

Search the FULL, uncompacted event log for a blackboard for events matching query — the retrieval-backed compaction technique. The underlying blackboard.logs list is never pruned by compaction (only the prompt string built from it is lossy), so this recovers detail a compacted summary may have dropped, scoped to a keyword query rather than dumping the entire history back.

Matching is a simple case-insensitive substring match against each event’s formatted text, keeping the most recent matches.

Parameters:
Return type:

List[Dict[str, Any]]

terrarium.core.blackboard.format_blackboard_events_for_prompt(events)[source]

Render blackboard event logs into a compact, readable transcript for prompts.

Parameters:

events (List[Dict[str, Any]])

Return type:

str

class terrarium.communication_protocols.base.BaseCommunicationProtocol[source]

Bases: ABC

Abstract interface for communication protocols.

A protocol coordinates agent turns, manages environment tool calls, and provides access to shared state (e.g., blackboards).

Communication protocol for managing multi-agent interactions and phases.

class terrarium.communication_protocols.sequential.SequentialCommunicationProtocol(config, tool_logger, run_timestamp=None)[source]

Bases: BaseCommunicationProtocol

Manages the overall communication protocol.

This class is environment-agnostic and handles: - Phase management (planning, execution) - Agent turn ordering and iteration

Parameters:
async agent_execution_turn(agent, agent_name, agent_context, environment, iteration)[source]

Handle a single agent’s execution turn with retry logic.

Parameters:
async agent_planning_turn(agent, agent_name, agent_context, environment, iteration, planning_round)[source]

Handle a single agent’s planning turn.

Parameters:
bind_environment(environment)[source]

Bind a concrete environment instance and initialize its tool handlers.

This resets blackboards so each simulation run starts clean.

Parameters:

environment (Any)

Return type:

None

async generate_comm_network(participants, context, template=None)[source]

Create a new blackboard and seed it with an initial context message.

Parameters:
  • participants – List of agent names that can access this blackboard.

  • context (str) – Initial context message to post as a system “context” event.

  • template (Dict[str, Any] | None) – Optional blackboard template.

Note

terrarium.communication_protocols.distributed is currently a placeholder module and is not included in the generated API reference.