This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
The Trader repo hosts the Olas prediction-market agents. A single agent package (valory/trader) is shipped as two services:
| Service | Stack name | Chain | Venue |
|---|---|---|---|
valory/trader_pearl |
Omenstrat | Gnosis | Omen |
valory/polymarket_trader |
Polystrat | Polygon | Polymarket (CLOB v2) |
Both run as single-agent (sovereign) deployments distributed via Pearl. The agent queries an AI Mech for probability estimates, evaluates profitability, and executes on-chain via a Safe multisig. Built on Open Autonomy (ABCI skills, FSMs, content-addressed packages); Tendermint is framework plumbing, not the deployment shape.
When working locally with make run-agent / aea-helpers run-agent, the agent-level aea-config.yaml defaults are Omen-flavored — service-level polymarket_trader/service.yaml overrides only apply under autonomy deploy. Local Polystrat dev requires explicit overrides (IS_RUNNING_ON_POLYMARKET=true, MECH_CHAIN_ID=polygon, DEFAULT_CHAIN_ID=polygon, pUSD-scaled STRATEGIES_KWARGS, the Polymarket TOOLS_ACCURACY_HASH, and the chain-specific market-filter flags). See README.md for the full set.
- Framework: Open Autonomy
- Package management:
uv(versions pinned inpyproject.toml— check there for the current Python range and dependencies; do not duplicate them here) - Task running:
Makefile+tox - Lint / format:
tomte(wraps black, isort, flake8, mypy, pylint, darglint, bandit) - Tests:
pytest+hypothesis
# Run all skill tests (pick the env that matches your interpreter; 3.10–3.14 supported)
uv run tox -e py3.10-linux # or py3.11/3.12/3.13/3.14-linux, *-darwin, etc.
# Run a single skill's tests
uv run pytest packages/valory/skills/<skill_name>/tests/ -v
# Run a specific test
uv run pytest packages/valory/skills/<skill_name>/tests/test_behaviours.py::TestClassName::test_method -vmake format # Auto-format (black + isort via tomte)
make code-checks # All linting: black, isort, flake8, mypy, pylint, darglint
make security # bandit + safety + gitleaks
make common-checks-1 # copyright, dependencies, linting
make common-checks-2 # hash check, package check, ABCI checks
make all-checks # Everything
make ci-linter-checks # CI linter checks (the full CI lint suite)make generators # Update hashes, copyright headers, ABCI docstrings
make sync-packages # Sync package versions across the repo
# Update FSM specs for a specific skill
autonomy analyse fsm-specs --update --app-class <AppClass> --package packages/valory/skills/<skill_name># Local single-agent dev loop (wraps `uv run aea-helpers run-agent --name valory/trader --connection-key`)
make run-agent
# Containerized service deployment (pick the flavor)
uv run autonomy fetch --local --service valory/trader_pearl # Omenstrat
uv run autonomy fetch --local --service valory/polymarket_trader # PolystratAfter autonomy packages sync, the layout looks like:
packages/valory/
├── agents/trader/ # The single agent definition (used by both services)
├── connections/ # polymarket_client (Polystrat CLOB v2), genai, x402, http_*, ipfs, ledger, ...
├── contracts/ # Smart contract interfaces (FPMM, Conditional Tokens, Realitio, Safe, ERC-20/1155, ...)
├── customs/ # Pluggable bet-sizing strategies: fixed_bet, kelly_criterion
├── services/
│ ├── trader_pearl/ # Omenstrat service (Gnosis / Omen)
│ └── polymarket_trader/ # Polystrat service (Polygon / Polymarket CLOB v2)
└── skills/
├── trader_abci/ # Main orchestrator / composed app
├── decision_maker_abci/ # Bet evaluation + placement (largest skill)
├── market_manager_abci/ # Market discovery (Omen + Polymarket variants)
├── mech_interact_abci/ # Mech communication
├── staking_abci/ # Staking management
├── tx_settlement_multiplexer_abci/ # Routes settlement transactions
├── check_stop_trading_abci/ # Pause/stop conditions
├── agent_performance_summary_abci/ # Performance + payout tracking
├── chatui_abci/ # Web UI hooks
└── funds_manager/ # Funds bookkeeping (uses RPC_URLS)
Every skill follows the Open Autonomy ABCI pattern — a finite state machine (FSM) replicated across agents via Tendermint consensus. Each skill contains:
rounds.py— State (Round) classes defining consensus logic and transitionsbehaviours.py— Behaviours that execute at each FSM state (one per round)payloads.py— Data payloads agents submit to reach consensushandlers.py— Message handlers for incoming protocol messagesmodels.py— Parameters (from YAML config) and shared statecomposition.py— FSM composition when orchestrating multiple skillsfsm_specification.yaml— Machine-readable FSM spec (auto-checked by CI)skill.yaml— Metadata, dependencies, and configuration with env var substitution (${VAR:type:default})
| Skill | Purpose |
|---|---|
market_manager_abci |
Fetches and filters tradeable prediction markets |
decision_maker_abci |
Core trading logic — evaluates bets for profitability (largest skill) |
mech_interact_abci |
Communicates with AI Mech for probability estimates |
staking_abci |
Agent staking management |
tx_settlement_multiplexer_abci |
Routes transactions to correct settlement handler |
check_stop_trading_abci |
Evaluates stop-trading conditions |
Skills are composed via chain() in trader_abci/composition.py, which wires FSM transitions across skills.
Trading strategies in packages/valory/customs/ are pluggable modules that determine bet sizing. Currently shipped: kelly_criterion (default) and fixed_bet. The active strategy is picked by the TRADING_STRATEGY env var; sizing parameters flow through STRATEGIES_KWARGS. Strategies are loaded by IPFS hash via the FILE_HASH_TO_STRATEGIES map.
Interfaces to on-chain contracts (FPMM market maker, conditional tokens, Realitio oracle, Gnosis Safe, etc.) live in packages/valory/contracts/.
- Python: range pinned in
pyproject.toml(currently 3.10–3.14) - Black formatting, 88-char line length
- isort with 3-line output mode and trailing commas
- Sphinx-style docstrings (enforced by darglint)
- Type hints required (mypy strict optional)
- Apache 2.0 copyright headers on all files (auto-checked)
- Encoding declaration:
# -*- coding: utf-8 -*-at top of files - All packages have content-addressed hashes checked in CI — run
make generatorsafter modifying package contents
- Tests live in
tests/subdirectories within each skill package - Run with pytest via tox (see Common Commands)
- Uses
unittest.mock.MagicMockfor mocking dependencies - Test classes with setup methods; parametrized tests common
- Coverage tracked via
.coveragerc - CI enforces 100% coverage — after making changes, run coverage against every file you modified, not just the primary one. Use
--cov=packages.valory.skills.<skill>.<module>for each changed module.
After modifying any package:
- Update FSM specs:
make fix-abci-app-specs - Regenerate hashes:
autonomy packages lock - Update copyrights: included in
make generators - Check ABCI docstrings:
tox -e check-abci-docstrings
After adding/removing dependencies:
- Update
pyproject.tomlandtox.ini([deps-packages] and [extra-deps] sections) - Run
uv lockthenuv sync --all-groups - Run
tox -e check-dependencies