Skip to main content

Adversarial quality loop for trading decisions

Project description

Crucible — Player-Coach

An adversarial quality loop for LLM-based trading decisions.

Player-Coach Demo

▶ Live dashboard · ▶ Watch the demo · PyPI


A PlayerAgent proposes trading actions; a CoachAgent evaluates every proposal mechanically against a formal constraint schema and rejects with a specific critique if any constraint is violated. The Player revises and resubmits for up to three rounds. The result is a structured artifact — every proposal, rejection, revision, and 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.


Dashboard

A five-page Streamlit app for running and reviewing player-coach exchanges.

Live demo: https://crucible-player-coach.streamlit.app

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.

Backtest — Compare two constraint presets over historical data side by side. Approval rate, average rounds, days aborted, total return, and max drawdown with winner highlighted per metric.


API key and database

API key: The dashboard uses a bring-your-own-key model. Enter your Anthropic API key in the Settings page. The key is stored in session memory only — it is never written to disk, logged, or shared between users. Each browser session is fully isolated.

Database: All exchanges are written to a shared SQLite database on the Streamlit Cloud instance. The History page shows exchanges from all users of the live demo. For private use, run the dashboard locally:

git clone https://github.com/MaverickHQ/crucible-player-coach
pip install player-coach-core[dashboard]
streamlit run dashboard/app.py

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.


Running locally

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']}")

Essays

Each essay is paired with a working implementation.

# Title Link
8 The Adversarial Quality Loop Read →
9 Building the Player-Coach Loop Read →
10 Closing the Evidence Loop Coming soon
11 The Quality of Reasoning Coming soon

Part of the Executable World Models series on harveygill.substack.com.


Demo

Player-Coach Demo

▶ Full demo video


Architecture

Component Role
PlayerAgent Proposes 1–3 actions given world state. Claude Haiku, max_tokens=1024.
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:

  1. MLL breached — peak drawdown exceeded, account terminated
  2. Daily loss limit — today's loss too large, skip today
  3. Consistency rule — today's gain exceeds fraction of cumulative, skip today
  4. 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

Project status

v1.1.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

player_coach_core-2.0.1-py3-none-any.whl (67.3 kB view details)

Uploaded Python 3

File details

Details for the file player_coach_core-2.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for player_coach_core-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8e5d6ab9fe3dd74aa2b99c3dfca9250ec49f12a6299ab8f64fbf87e66ad9c2b4
MD5 54ba75207cb94584474b66f021129adf
BLAKE2b-256 54747e5aa296f510a89f196eca0442e8307ddcc7ac55d1acdb5ac27476f0d2d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page