Core

Blackboard classes are documented under Communication.

Async Utilities

async terrarium.core.async_utils.run_blocking(func, /, *args, **kwargs)[source]

Run a blocking function in a shared thread pool without blocking the asyncio loop.

Parameters:
Return type:

T

Logging

class terrarium.core.logger.AgentTrajectoryLogger(environment_name='Unknown', seed=0, config=None, run_timestamp=None, log_dir=None)[source]

Bases: object

Logger for capturing agent reasoning and tool call trajectories.

Logs the internal decision-making process of agents including: - Reasoning text (from response.output_text) - Tool calls with parameters - Organized by agent → iteration → phase → trajectory steps

Initialize the agent trajectory logger.

Parameters:
  • environment_name (str) – Name of the environment (e.g., “Hospital”, “SmartGrid”)

  • seed (int) – Simulation seed for unique log files

  • config (Dict[str, Any]) – Full configuration dictionary containing all simulation settings

  • run_timestamp (str | None)

  • log_dir (Path | None)

log_trajectory(agent_name, iteration, phase, trajectory_dict, round_num=None)[source]

Log a trajectory for an agent during a specific iteration and phase.

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

  • iteration (int) – Current iteration number

  • phase (str) – Current phase (planning, execution)

  • trajectory_dict (Dict[str, Any]) – Dictionary of trajectory steps with keys like “step_1”, “step_2” Each step contains: - tools: List of tool calls formatted as “{tool_name} – {parameters}” - reasoning: Reasoning text (from response.output_text)

  • round_num (int | None) – Round number (for planning phase only, None for execution)

Return type:

None

reset_log()[source]

Reset the agent trajectory log by clearing all entries.

class terrarium.core.logger.AttackLogger(environment_name, seed, config, run_timestamp=None)[source]

Bases: object

Structured logger for attack executions and outcomes.

Parameters:
reset_log()[source]

Reset attack logs for a fresh simulation run.

Return type:

None

class terrarium.core.logger.BlackboardLogger(config, run_timestamp=None)[source]

Bases: object

Logger specifically for tracking the complete blackboard state.

Saves the entire blackboard after each agent interaction, providing a complete view of all agent communications and their evolution. Now supports multiple blackboards with separate log files.

Initialize the blackboard logger.

Parameters:
  • config (Dict[str, Any]) – Full configuration dictionary containing all simulation settings

  • run_timestamp (str | None) – Optional run timestamp override for log directory naming

clear_blackboard_logs()[source]

Clear all blackboard log files and reset tracking. Called at the start of each simulation.

log_blackboard_creation(blackboard_id, participants, initial_context='', inviter='')[source]

Log the creation of a new blackboard.

Parameters:
  • blackboard_id (str) – ID of the new blackboard

  • participants (List[str]) – List of agents participating in the blackboard

  • initial_context (str) – Purpose/context of the blackboard

  • inviter (str) – Agent who created the blackboard (if applicable)

log_blackboard_exit(blackboard_id, agent_name)[source]

Log an agent exiting a blackboard.

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

  • agent_name (str) – Name of the agent exiting

log_blackboard_join(blackboard_id, agent_name)[source]

Log an agent joining a blackboard.

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

  • agent_name (str) – Name of the agent joining

log_blackboard_state(blackboard, iteration=0, phase='unknown', agent_name='', round_num=None)[source]

Log the complete current state of the blackboard.

Parameters:
  • blackboard (Blackboard) – The blackboard instance to log

  • iteration (int) – Current iteration number

  • phase (str) – Current phase (planning/execution)

  • agent_name (str) – Name of agent that just acted (optional)

  • round_num (int | None) – Round number within the phase (optional)

class terrarium.core.logger.PromptLogger(environment_name='Unknown', seed=0, config=None, run_timestamp=None, log_dir=None)[source]

Bases: object

Logger for capturing agent prompts (system and user) in both JSON and Markdown formats.

Parameters:
log_prompts(agent_name, system_prompt, user_prompt, phase, iteration=None, round_num=None)[source]

Log both system and user prompts with metadata in JSON and Markdown formats.

Parameters:
  • agent_name (str)

  • system_prompt (str)

  • user_prompt (str)

  • phase (str)

  • iteration (int | None)

  • round_num (int | None)

Return type:

None

reset_log()[source]

Reset both JSON and Markdown prompt logs by clearing all entries.

class terrarium.core.logger.ToolCallLogger(environment_name='Unknown', seed=0, config=None, run_timestamp=None)[source]

Bases: object

Logger for capturing all tool calls with metadata.

Logs all tool invocations including agent name, phase, iteration/round, function name, parameters, result, and timing information.

Initialize the tool call logger.

Parameters:
  • environment_name (str) – Name of the environment (e.g., “Hospital”, “SmartGrid”)

  • seed (int) – Simulation seed for unique log files

  • config (Dict[str, Any]) – Full configuration dictionary containing all simulation settings

  • run_timestamp (str | None)

log_adversarial_agent_action(agent_name, original_message, replaced_message, phase, iteration=None, round_num=None)[source]

Log when an adversarial_agent agent’s message is replaced.

Parameters:
  • agent_name (str)

  • original_message (str)

  • replaced_message (str)

  • phase (str)

  • iteration (int | None)

  • round_num (int | None)

log_tool_call(agent_name, phase, tool_name, parameters, result, iteration=None, round_num=None, duration_ms=None)[source]

Log a tool call with all relevant metadata.

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

  • phase (str) – Current phase (planning, execution, etc.)

  • tool_name (str) – Name of the tool/function being called

  • parameters (Dict[str, Any]) – Parameters passed to the tool

  • result (Dict[str, Any]) – Result returned from the tool

  • iteration (int | None) – Current iteration number (for execution phase)

  • round_num (int | None) – Current round number (for planning phase)

  • duration_ms (float | None) – Time taken to execute the tool in milliseconds

Return type:

None

reset_log()[source]

Reset the tool call log by clearing all entries.