Utilities¶
Utility functions for the communication protocol framework.
This module provides shared utility functions used across different environments and components of the multi-agent communication protocol system.
- terrarium.utils.build_log_dir(environment_name, tag_model, seed, run_timestamp=None, *, log_root='logs')[source]¶
Build the filesystem path for log artifacts.
- terrarium.utils.build_vllm_runtime(llm_config)[source]¶
Construct a VLLMProviderRuntime from normalized configuration.
- terrarium.utils.clear_seed_directories(environment_name, seed, full_config)[source]¶
Clear existing seed directories for both logs and plots to ensure clean state.
- terrarium.utils.configure_client_external_mcp(client, llm_config)[source]¶
Attach optional external MCP server configuration to a client instance.
- terrarium.utils.create_environment(protocol, environment_name, config, tool_logger)[source]¶
Create environment instance based on name.
- Parameters:
protocol – Communication protocol instance
environment_name (str) – Environment class name (matches config environment.name)
config – Configuration dictionary
tool_logger – Tool call logger instance
- Returns:
Instantiated environment object
- Raises:
ValueError – If environment name is unknown
- Return type:
- terrarium.utils.extract_model_info(full_config)[source]¶
Extract model name from full config for logging.
- terrarium.utils.get_client_instance(llm_config, *, agent_name=None, vllm_runtime=None)[source]¶
Create and return the appropriate LLM client based on provider configuration.
- Parameters:
- Returns:
Instantiated client (OpenAI/Foundry/Grok/Anthropic/Gemini/Together/Fireworks/VLLM)
- Raises:
ValueError – If provider is unknown
NotImplementedError – If vllm provider is selected (currently not implemented)
- terrarium.utils.get_implemented_environment_names()[source]¶
Return the list of supported environment.name values.
- terrarium.utils.get_log_root_dir(full_config=None, default='logs')[source]¶
Resolve the base directory used for writing run log artifacts.
By default, logs are written under the repo-root logs/ folder. Experiment runners can override this to keep artifacts self-contained by setting:
- logging:
root_dir: experiments/<project>/outputs/<tag>/<timestamp>/runs/<…>/logs
- terrarium.utils.get_model_name(provider, llm_config)[source]¶
Extract model name based on provider from LLM configuration.
- Parameters:
- Returns:
Model name string
- Raises:
ValueError – If provider is unknown
NotImplementedError – If vllm provider is selected (currently not implemented)
- Return type:
- terrarium.utils.get_run_timestamp(full_config, default=None)[source]¶
Return the run timestamp stored in the simulation config, if any.
- terrarium.utils.get_tag_model_subdir(full_config)[source]¶
Generate tag_model subdirectory name from configuration.
- terrarium.utils.load_config(config_file)[source]¶
Load and validate configuration from YAML file.
- Parameters:
config_file – Path to YAML configuration file
- Returns:
Validated configuration dictionary
- Raises:
FileNotFoundError – If config file does not exist
ValueError – If config validation fails
- Return type:
- terrarium.utils.load_seeds(seeds_file='seeds.txt')[source]¶
Load simulation seeds from text file for reproducibility.