This section is for advanced use cases. If you’re building a single agent, you can skip this entirely.
The CLI supports monorepo setups where multiple agents share utility code.
Important: Each agent’s dependency file (pyproject.toml for Python, package.json for TypeScript) should include the dependencies for any shared utils being used.
Monorepo Structure
The recommended structure uses separate directories for agents and shared utilities:
my-circuit-agents/
├── agents/
│ ├── sample-agent-1/
│ │ ├── main.py
│ │ ├── DESCRIPTION.md
│ │ ├── circuit.toml
│ │ └── pyproject.toml
│ ├── sample-agent-2/
│ │ ├── main.py
│ │ ├── DESCRIPTION.md
│ │ ├── circuit.toml
│ │ └── pyproject.toml
└── utils/
├── __init__.py
├── polymarket/
│ ├── __init__.py
│ └── trading.py
├── hyperliquid/
│ ├── __init__.py
│ └── positions.py
└── analytics/
├── __init__.py
└── metrics.py
Setting Up Shared Utilities
1. Create the Utils Package
Create a utils/ directory at your monorepo root with proper package structure:
# From your monorepo root
mkdir -p utils/polymarket utils/hyperliquid utils/analytics
touch utils/__init__.py
touch utils/polymarket/__init__.py
touch utils/hyperliquid/__init__.py
touch utils/analytics/__init__.py
2. Export Functions in Module Index Files
Make your utility functions easily importable by exporting them:
# utils/polymarket/__init__.py
from .trading import get_positions, place_order
__all__ = [
"get_positions",
"place_order",
]
In each agent’s circuit.toml, specify which shared directories to include:
# agents/trading-bot/circuit.toml
name = "Trading Bot"
# ... other config ...
# Include all shared utilities
filesToInclude = ["../../utils"]
# Or include only specific subdirectories
# filesToInclude = ["../../utils/polymarket", "../../utils/analytics"]
Note: The filesToInclude configuration works the same for both Python and TypeScript agents.
Set up module resolution to enable imports in local development.
Python: Add these lines at the top of your agent’s main.py. This adds your monorepo root to Python’s search path, which is needed because Python doesn’t automatically look in parent directories.
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent))
# Now you can import shared utilities
from utils.polymarket import get_positions, place_order
from utils.analytics import calculate_sharpe_ratio
TypeScript: Configure your agent’s tsconfig.json with path aliases, then import using the alias:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/*": ["../../*"]
}
}
}
import { getPositions, placeOrder } from '~/utils/polymarket';
import { calculateSharpeRatio } from '~/utils/analytics';