Environments API

Base Environment

Abstract base class for environments.

This module defines the interface that all environments must implement to work with the CommunicationProtocol. It separates environment-specific logic from the generic communication and phase management.

class terrarium.environments.abstract_environment.AbstractEnvironment[source]

Bases: ABC

Abstract base class for environments that can be used with CommunicationProtocol.

This interface defines the minimal set of methods that any environment must implement to integrate with the communication protocol system. The protocol handles phases, iterations, blackboard management, and LLM interactions, while the environment handles domain-specific logic, actions, and context.

Variables:
  • blackboard_logger (terrarium.core.logger.BlackboardLogger | None) – Optional logger for tracking blackboard state changes. Environments should initialize this in their initialize() method if they want blackboard logging. Set to None to disable logging.

  • prompt_logger (terrarium.core.logger.PromptLogger | None) – Optional logger for tracking agent prompts (system and user). Environments should initialize this in their initialize() method if they want prompt logging. Set to None to disable logging.

abstractmethod agent_reward(agent_name, action)[source]

Compute the reward for a single agent given its action. Allows credit assignment of agent actions to joint reward.

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

  • action (Any) – The action taken by the agent

Return type:

float

assignment_filling_enabled()[source]

Return whether the environment should fill unassigned decisions in summaries.

Controlled by environment.assignment_filling in the run config (default: True).

Return type:

bool

async async_init()[source]

Async initialization hook (default: create blackboards from the supplied network).

Return type:

None

abstractmethod build_agent_context(agent_name, phase, iteration, **kwargs)[source]

Build environment-specific context for an agent’s turn.

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

  • phase (str) – Current phase (“planning” or “execution”)

  • iteration (int) – Current iteration number

  • **kwargs – Additional context (planning_round, etc.)

Returns:

Dictionary with agent context including –

  • Agent state (budget, inventory, utilities)

  • Environment state (store, available items)

  • Phase-specific information

  • Any other relevant context

Return type:

Dict[str, Any]

The protocol will pass this context to get_user_prompt along with blackboard contexts and available tools.

abstractmethod compute_max_joint_reward()[source]

Compute the maximum joint reward achievable in this environment.

Returns:

Optimal joint reward as a float

Return type:

float

abstractmethod done(iteration)[source]

Check if the simulation is complete.

Parameters:

iteration (int) – Current iteration number

Returns:

True if the simulation should stop, False to continue.

Return type:

bool

format_blackboard_context(participants, base_context)[source]

Format the initial blackboard context for a given channel.

Parameters:
Return type:

str

generate_final_summary()[source]

Log and return a final summary of the simulation.

Return type:

Dict[str, Any]

get_agent_names()[source]

Get the list of all agent names in this environment.

Returns:

List of agent name strings

Return type:

List[str]

This is used by the protocol to iterate through agents during phases.

get_final_summary()[source]

Get a final summary of the entire simulation.

Returns:

Dictionary with final simulation results

Return type:

Dict[str, Any]

Default implementation returns empty summary. Environments can override to provide meaningful final statistics and results.

get_network_context()[source]

Return the base context message to seed every communication blackboard.

Return type:

str

async initialize_communication_network()[source]

Create blackboards for the supplied communication network

Return type:

None

abstractmethod joint_reward(actions)[source]

Compute a joint reward given agent actions. Can be a function of all agents’ individual rewards using agent_reward().

Parameters:

actions (Mapping[str, Any]) – A mapping from agent names to their actions

Return type:

float

log_iteration_summary(iteration)[source]

Log a summary header for an iteration then delegate to log_iteration().

Parameters:

iteration (int)

Return type:

None

set_agent_clients(agents)[source]

Set the instantiated agent clients for the environment.

The protocol typically calls this after constructing the LLM-backed agents. Environments can override if they need additional bookkeeping.

Parameters:

agents (List[Any])

Return type:

None

set_communication_network(communication_network)[source]

Attach a pre-built communication network to this environment.

The network is expected to be NetworkX graph and expose: - agent_names: List[str] - validate_agents(agent_names: Sequence[str]) - channel_groups() -> List[List[str]]

Parameters:

communication_network (CommunicationNetwork)

Return type:

None

Implemented Environments

class terrarium.environments.dcops.meeting_scheduling.meeting_scheduling_env.MeetingSchedulingEnvironment(communication_protocol, config, tool_logger)[source]

Bases: AbstractEnvironment

MeetingScheduling environment adaptor for attendance‑interval coordination tasks.

Agents decide how long to attend each meeting they are assigned to, aiming to maximize joint reward while avoiding overlaps.

Initialize the MeetingScheduling environment.

agent_reward(actions, agent)[source]

Return the reward attributed to a single agent.

Parameters:
Return type:

float

async async_init()[source]

Async initialization hook (default: create blackboards from the supplied network).

build_agent_context(agent_name, phase, iteration, **kwargs)[source]

Build environment-specific context for an agent’s turn.

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

  • phase (str) – Current phase (“planning” or “execution”)

  • iteration (int) – Current iteration number

  • **kwargs – Additional context

Returns:

Dictionary with agent context

Return type:

Dict[str, Any]

compute_max_joint_reward()[source]

Return the optimal joint reward for the environment.

Return type:

float

done(iteration)[source]

Return True when the environment is finished.

Parameters:

iteration (int)

Return type:

bool

get_final_summary()[source]

Get a final summary of the entire simulation.

Return type:

Dict[str, Any]

joint_reward(actions)[source]

Return the joint reward for a joint assignment.

Parameters:

actions (Mapping[str, Any])

Return type:

float

log_iteration(iteration)[source]

Log the current state of the environment.

Parameters:

iteration (int) – Current iteration number

Return type:

None

class terrarium.environments.dcops.personal_assistant.personal_assistant_env.PersonalAssistantEnvironment(communication_protocol, config, tool_logger)[source]

Bases: AbstractEnvironment

PersonalAssistant environment adaptor for outfit coordination tasks.

Agents coordinate to select outfits that satisfy personal preferences and inter-agent constraints (color matching/avoiding).

Initialize the PersonalAssistant environment.

agent_reward(actions, agent)[source]

Return the reward attributed to a single agent.

Parameters:
Return type:

float

async async_init()[source]

Async initialization - create communication blackboards from the supplied network.

build_agent_context(agent_name, phase, iteration, **kwargs)[source]

Build environment-specific context for an agent’s turn. This is used in the planning and execution phases in CommunicationProtocol.

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

  • phase (str) – Current phase (“planning” or “execution”)

  • iteration (int) – Current iteration number

  • **kwargs – Additional context

Returns:

Dictionary with agent context

Return type:

Dict[str, Any]

compute_max_joint_reward()[source]

Return the optimal joint reward for the environment.

Return type:

float

done(iteration)[source]

Return True when the environment is finished.

Parameters:

iteration (int)

Return type:

bool

get_final_summary()[source]

Get a final summary of the entire simulation.

Return type:

Dict[str, Any]

joint_reward(actions)[source]

Return the (partial) joint reward for a joint assignment.

Parameters:

actions (Mapping[str, Any])

Return type:

float

log_iteration(iteration)[source]

Log the current state of the environment.

Parameters:

iteration (int) – Current iteration number

Return type:

None

class terrarium.environments.dcops.smart_grid.smart_grid_env.SmartGridEnvironment(communication_protocol, config, tool_logger)[source]

Bases: AbstractEnvironment

SmartGrid environment adaptor for CoLLAB v2 renewable source allocation.

agent_reward(actions, agent)[source]

Return the reward attributed to a single agent.

Parameters:
Return type:

float

async async_init()[source]

Async initialization hook (default: create blackboards from the supplied network).

build_agent_context(agent_name, phase, iteration, **kwargs)[source]

Build environment-specific context for an agent’s turn.

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

  • phase (str) – Current phase (“planning” or “execution”)

  • iteration (int) – Current iteration number

  • **kwargs – Additional context (planning_round, etc.)

Returns:

Dictionary with agent context including –

  • Agent state (budget, inventory, utilities)

  • Environment state (store, available items)

  • Phase-specific information

  • Any other relevant context

Return type:

Dict[str, Any]

The protocol will pass this context to get_user_prompt along with blackboard contexts and available tools.

compute_max_joint_reward()[source]

Return the optimal joint reward for the environment.

Return type:

float

done(iteration)[source]

Return True when the environment is finished.

Parameters:

iteration (int)

Return type:

bool

get_final_summary()[source]

Get a final summary of the entire simulation.

Returns:

Dictionary with final simulation results

Return type:

Dict[str, Any]

Default implementation returns empty summary. Environments can override to provide meaningful final statistics and results.

joint_reward(actions)[source]

Return the (partial) joint reward for a joint assignment.

Parameters:

actions (Mapping[str, Any])

Return type:

float

class terrarium.environments.dcops.hospital.hospital_env.HospitalEnvironment(communication_protocol, config, tool_logger)[source]

Bases: AbstractEnvironment

agent_reward(agent_name, action)[source]

Compute the reward for a single agent given its action. Allows credit assignment of agent actions to joint reward.

Parameters:
  • agent_name – Name of the agent

  • action – The action taken by the agent

async async_init()[source]

Async initialization hook (default: create blackboards from the supplied network).

build_agent_context(agent_name, phase, iteration, **kwargs)[source]

Build environment-specific context for an agent’s turn.

Parameters:
  • agent_name – Name of the agent

  • phase – Current phase (“planning” or “execution”)

  • iteration – Current iteration number

  • **kwargs – Additional context (planning_round, etc.)

Returns:

Dictionary with agent context including –

  • Agent state (budget, inventory, utilities)

  • Environment state (store, available items)

  • Phase-specific information

  • Any other relevant context

The protocol will pass this context to get_user_prompt along with blackboard contexts and available tools.

compute_max_joint_reward()[source]

Compute the maximum joint reward achievable in this environment.

Returns:

Optimal joint reward as a float

Return type:

float

done(iteration)[source]

Check if the simulation is complete.

Parameters:

iteration – Current iteration number

Returns:

True if the simulation should stop, False to continue.

get_final_summary()[source]

Get a final summary of the entire simulation.

Returns:

Dictionary with final simulation results

Default implementation returns empty summary. Environments can override to provide meaningful final statistics and results.

get_network_context()[source]

Return the base context message to seed every communication blackboard.

joint_reward(actions)[source]

Compute a joint reward given agent actions. Can be a function of all agents’ individual rewards using agent_reward().

Parameters:

actions – A mapping from agent names to their actions

class terrarium.environments.dcops.jira_ticket.jira_ticket_env.JiraTicketEnvironment(communication_protocol, config, tool_logger)[source]

Bases: AbstractEnvironment

JIRA ticket assignment DCOP environment.

Initialize synthetic JIRA task environment and compute cost tables.

agent_reward(actions, agent)[source]

Return the reward attributed to a single agent.

Parameters:
Return type:

float

build_agent_context(agent_name, phase, iteration, **kwargs)[source]

Assemble per-agent prompt context for the current phase/iteration.

Parameters:
  • agent_name (str)

  • phase (str)

  • iteration (int)

Return type:

Dict[str, Any]

compute_max_joint_reward()[source]

Return a theoretical upper bound of the joint reward (no solver).

Return type:

float

done(iteration)[source]

Stop when max iterations reached or all agents have decided.

Parameters:

iteration (int)

Return type:

bool

get_final_summary()[source]

Return run-level summary including coverage and normalized score.

Return type:

Dict[str, Any]

get_network_context()[source]

Return base context string shown on each blackboard channel.

Return type:

str

joint_reward(actions)[source]

Return joint score for a given partial/complete assignment.

Parameters:

actions (Mapping[str, Any])

Return type:

float

log_iteration(iteration)[source]

Log current state and scores for this iteration.

Parameters:

iteration (int)

Return type:

None

Prompt Helpers

class terrarium.environments.dcops.meeting_scheduling.meeting_scheduling_prompts.MeetingSchedulingPrompts(env, full_config)[source]

Prompt builder for the CoLLAB v2 MeetingScheduling environment.

Agents decide attendance intervals for each meeting they participate in.

Parameters:
class terrarium.environments.dcops.personal_assistant.personal_assistant_prompts.PersonalAssistantPrompts(env, full_config)[source]

Prompt builder for CoLLAB v2 PersonalAssistant environment.

Agents each choose one numbered outfit from their wardrobe.

Parameters:
class terrarium.environments.dcops.smart_grid.smartgrid_prompts.SmartGridPrompts(env, full_config)[source]
Parameters:
class terrarium.environments.dcops.hospital.hospital_prompts.HospitalPrompts(env, config)[source]
class terrarium.environments.dcops.jira_ticket.jira_ticket_prompts.JiraTicketPrompts(env, full_config)[source]

Prompt builder for the JiraTicket DCOP environment.

Parameters: