openmas run
Command¶
The openmas run
command is a cornerstone of the OpenMAS developer experience, designed for local execution and debugging of a single agent within a multi-agent system. It functions similarly to dbt run
in its role within the development loop.
Usage¶
Where:
- <agent_name>
is the name of an agent defined in your project's openmas_project.yml
file.
- --project-dir PATH
(optional) is an explicit path to the project directory containing the openmas_project.yml
file.
Purpose¶
This command provides a standardized, framework-aware way to run and test individual agents locally. It:
- Finds your project root (location of
openmas_project.yml
) - Loads the complete, layered configuration stack
- Sets up Python paths for imports from
shared/
andextensions/
directories - Dynamically loads and instantiates the specified agent
- Executes the agent's lifecycle methods (
setup()
,run()
, andshutdown()
) viaasyncio
- Blocks the terminal while the agent's
run()
method executes - Provides guidance for running other agents in separate terminals
- Gracefully handles signals (Ctrl+C) to ensure proper shutdown
Configuration Loading¶
When running an agent, configuration is loaded in the following order (lowest to highest precedence):
- OpenMAS SDK internal defaults (defined in Pydantic models)
default_config
section inopenmas_project.yml
config/default.yml
fileconfig/<OPENMAS_ENV>.yml
file (defaults tolocal.yml
ifOPENMAS_ENV
is not set).env
file at project root- Environment variables (highest precedence)
This layered approach allows for flexible configuration management across different environments.
Running Multiple Agents¶
To run a full multi-agent system locally, you need to:
- Open a separate terminal window for each agent
- Run each agent with
openmas run <agent_name>
After successfully starting an agent, if your project contains multiple agents, the command will display a helpful guidance message suggesting how to run the other agents in your project.
Example¶
# In terminal 1
$ openmas run orchestrator
Starting agent 'orchestrator' (OrchestratorAgent)
Setting up agent...
[OpenMAS CLI] Agent start success.
[OpenMAS CLI] To run other agents in this project, open new terminal windows and use:
[OpenMAS CLI] openmas run worker1
[OpenMAS CLI] openmas run worker2
[OpenMAS CLI] Project agents: orchestrator, worker1, worker2
# In terminal 2
$ openmas run worker1
...
# In terminal 3
$ openmas run worker2
...
Example with project directory specified¶
# Running from outside the project directory
$ openmas run orchestrator --project-dir /path/to/my/project
Starting agent 'orchestrator' (OrchestratorAgent)
Setting up agent...
Graceful Shutdown¶
The command handles SIGINT
(Ctrl+C) and SIGTERM
signals gracefully, ensuring that:
- The agent's
run()
method is cancelled or completes - The agent's
shutdown()
method is called to perform cleanup - The process exits cleanly
Python Path Management¶
When running an agent, the command automatically sets up the Python path to include:
- The project root directory
- The agent's parent directory
- All directories listed in
shared_paths
in your project configuration - All directories listed in
extension_paths
in your project configuration
This enables imports from shared modules and extensions without requiring manual PYTHONPATH
manipulation.
Error Handling¶
The command provides specific and informative error messages for common issues:
- Missing project configuration
- Agent not found in configuration
- Missing agent module file
- Import errors
- No BaseAgent subclass found
- Exceptions during agent setup, run, or shutdown
Related Commands¶
openmas init
: Initialize a new OpenMAS projectopenmas validate
: Validate project configurationopenmas list agents
: List agents defined in the project