Adversarial quality loop for trading decisions
Project description
Crucible Player-Coach
An adversarial quality loop for trading decisions. A CoachAgent challenges and refines a PlayerAgent's proposals before execution. Every proposal, rejection, revision, and approval is recorded as a structured artifact.
Part of the Crucible project series — see also crucible-ewm.
How it works
The PlayerAgent proposes trading actions given the current market state. The CoachAgent evaluates every proposal against a formal constraint schema — mechanically, against numbers, not vaguely. If the proposal violates a constraint, the Coach rejects it with a specific critique. The Player revises and resubmits. This continues for up to three rounds.
The result is not just a trading decision. It is a structured artifact: every proposal, every rejection, every revision, every approval — recorded, validated, and queryable.
Installation
# Core infrastructure
pip install player-coach-core
# With LLM agents
pip install player-coach-core[llm]
# With Streamlit dashboard
pip install player-coach-core[dashboard]
Requires ANTHROPIC_API_KEY for LLM agents.
Quick start
from player_coach.agents.player import PlayerAgent
from player_coach.agents.coach import CoachAgent
from player_coach.artifacts.writer import ArtifactWriter
from player_coach.constraints.schema import ConstraintSchema
from player_coach.loop.coach_loop import CoachLoop
import json
from pathlib import Path
constraints = ConstraintSchema.from_dict(
json.loads(Path("examples/constraints/moderate.json").read_text())
)
loop = CoachLoop(
player=PlayerAgent(),
coach=CoachAgent(),
artifact_writer=ArtifactWriter("artifacts"),
)
artifact = loop.run(
world_state={
"symbol": "AMZN", "price": 185.0,
"sma5": 183.0, "sma10": 180.0,
"volume": 45_000_000, "position": "flat",
"volatility_regime": "medium", "session": "NY_open",
},
constraints=constraints,
)
print(f"Outcome: {artifact['outcome']}")
print(f"Rounds: {artifact['rounds_taken']}")
Dashboard
A four-page Streamlit app for running and reviewing player-coach exchanges.
streamlit run dashboard/app.py
Trade Review — Run a live exchange. Player and Coach characters animate with streaming speech bubbles. Round cards show proposals, verdicts, violations, and critique.
Constraints — Configure the Coach's constraint schema. Load presets, adjust sliders, export JSON, or push directly to the Trade Review page.
History — Browse past exchanges from SQLite. Filter by outcome. Select any row to inspect rounds and replay with animation.
Settings — BYOK API key entry and validation. Key lives in session memory only, never stored.
Constraint schema
{
"max_position_pct": 0.15,
"max_single_trade_pct": 0.05,
"max_leverage": 1.5,
"max_drawdown_pct": 0.10,
"max_daily_loss_pct": 0.02,
"consistency_rule_pct": 0.50,
"trading_cutoff_time": "16:20",
"allowed_symbols": ["AMZN", "MSFT", "TSLA", "BTC-USD"],
"max_open_positions": 3,
"min_risk_reward": 1.5,
"max_rounds": 3,
"abort_on_violations": ["max_leverage", "max_drawdown_pct"]
}
Five presets in examples/constraints/:
conservative, moderate, aggressive,
strict, futures_compatible.
Architecture
| Component | Role |
|---|---|
PlayerAgent |
Proposes 1–3 actions given world state. Claude Haiku, max_tokens=512. |
CoachAgent |
Evaluates proposals against constraint schema. max_tokens=1024. |
CoachLoop |
Orchestrates exchange. Up to 3 rounds. Writes artifact to disk and SQLite. |
circuit_breakers |
MLL, daily loss limit, consistency rule, trading cutoff — pure functions. |
ConstraintDeriver |
Derives constraint schema from ewm-core evidence policy. |
BacktestRunner |
Replays CoachLoop over historical trading days via yfinance. |
DatabaseStore |
SQLite persistence for exchanges, rounds, strategies, portfolio snapshots. |
Circuit breakers
Four hard stops checked before every round, in priority order:
- MLL breached — peak drawdown exceeded, account terminated
- Daily loss limit — today's loss too large, skip today
- Consistency rule — today's gain exceeds fraction of cumulative, skip today
- Trading cutoff — market hours ended, skip today
Related
| Repo | What |
|---|---|
| crucible-ewm | Observable agent trajectories, evidence policy, ewm-core |
| beyond-tokens | Constrained LLM planning on AWS Bedrock |
Essays
| Essay | Description |
|---|---|
| Essay 8a — Theory (coming soon) | Adversarial quality in agent systems |
| Essay 8b — Implementation (coming soon) | How player-coach works |
Published on Substack.
Project status
v1.0.0 — complete. Backend, dashboard, tests, and PyPI package all shipped.
Backlog: AWS AgentCore deployment — PlayerAgent and CoachAgent as separate Lambda functions, Step Functions orchestration, artifacts to S3.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file player_coach_core-1.0.1.tar.gz.
File metadata
- Download URL: player_coach_core-1.0.1.tar.gz
- Upload date:
- Size: 54.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4b990a1ac6e2cabf1921c0e8270482d1d1a3ba82bb2f11ecf82ceb9dc191a34
|
|
| MD5 |
388e11c5f5bd552c0f0c1c03f4e92de1
|
|
| BLAKE2b-256 |
f72ecd4713a6a52dd9a2825a63aec4d19e9f0cb033f649e83186f3a1a545af15
|
File details
Details for the file player_coach_core-1.0.1-py3-none-any.whl.
File metadata
- Download URL: player_coach_core-1.0.1-py3-none-any.whl
- Upload date:
- Size: 20.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bede03c5a344ec9163eaa24c22a531b0a15bba377d3581ae2714e41f5d8235e9
|
|
| MD5 |
3d47b9b65cb47a957a3e825291e83fe4
|
|
| BLAKE2b-256 |
6ecc395f7e1410ceb1b288b7e0fc7af6f57831758bdf631e620f9ce463d32bf9
|