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:
ABCAbstract 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.
- 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:
- 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:
- 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:
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:
- format_blackboard_context(participants, base_context)[source]¶
Format the initial blackboard context for a given channel.
- get_agent_names()[source]¶
Get the list of all agent names in this environment.
This is used by the protocol to iterate through agents during phases.
- get_final_summary()[source]¶
Get a final summary of the entire simulation.
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:
- 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().
- 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.
- 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:
AbstractEnvironmentMeetingScheduling 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.
- 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.
- compute_max_joint_reward()[source]¶
Return the optimal joint reward for the environment.
- Return type:
- class terrarium.environments.dcops.personal_assistant.personal_assistant_env.PersonalAssistantEnvironment(communication_protocol, config, tool_logger)[source]¶
Bases:
AbstractEnvironmentPersonalAssistant 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.
- 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.
- compute_max_joint_reward()[source]¶
Return the optimal joint reward for the environment.
- Return type:
- class terrarium.environments.dcops.smart_grid.smart_grid_env.SmartGridEnvironment(communication_protocol, config, tool_logger)[source]¶
Bases:
AbstractEnvironmentSmartGrid environment adaptor for CoLLAB v2 renewable source allocation.
- 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:
- 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:
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:
- 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:
- 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.
- class terrarium.environments.dcops.jira_ticket.jira_ticket_env.JiraTicketEnvironment(communication_protocol, config, tool_logger)[source]¶
Bases:
AbstractEnvironmentJIRA ticket assignment DCOP environment.
Initialize synthetic JIRA task environment and compute cost tables.
- build_agent_context(agent_name, phase, iteration, **kwargs)[source]¶
Assemble per-agent prompt context for the current phase/iteration.
- compute_max_joint_reward()[source]¶
Return a theoretical upper bound of the joint reward (no solver).
- Return type:
- get_network_context()[source]¶
Return base context string shown on each blackboard channel.
- Return type:
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:
env (AbstractEnvironment)
- 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:
env (AbstractEnvironment)
- class terrarium.environments.dcops.smart_grid.smartgrid_prompts.SmartGridPrompts(env, full_config)[source]¶
- Parameters:
env (AbstractEnvironment)