Skip to content

AI Strategy: model-native strategy with shadow warm-up and improve loops - #13

Draft
anomaddev wants to merge 21 commits into
mainfrom
ai-strategy-build
Draft

anomaddev wants to merge 21 commits into
mainfrom
ai-strategy-build

Conversation

@anomaddev

@anomaddev anomaddev commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Summary

Implements the AI Strategy master plan across four slices on ai-strategy-build, plus a post-implementation hardening pass before spin-up.

Slice 1 — Foundations + shadow warm-up

  • ai_strategy preset (forex-only) with fail-closed evaluator
  • params.ai schema persistence + docs
  • Isolated shadow_intents / shadow_lots / trade_outcome_records / strategy_guidance
  • ET trading-day warm-up lifecycle + POST /api/strategies/{id}/promote
  • LLM budget reserve/settle + kill switch (BROKERAI_LLM_KILL_SWITCH)
  • Priority policy so warming AI cannot starve live EMA
  • FE builder, phase chips, promote CTA, warm-up progress

Slice 2 — Model runtime

  • ModelSignalRuntime with throttled LLM decisions (llm_mode, interval, spend gate)
  • Guidance bias injection; async run_strategy_analysis
  • Builder model / LLM mode / learn controls

Slice 3 — Outcome learning

  • Batched learning_jobsstrategy_memory_digests
  • Shadow close queues learn jobs (no per-close LLM)
  • Secretary drains queued learning jobs (1/tick)
  • Digest injected into model prompts

Slice 4 — Daily compiled backtests

  • Deterministic compiled_playbook signal (no LLM in BT bar loop)
  • Secretary daily queue (ET cadence, default off)
  • Auto AI feedback forked into memory (FE Apply-in-builder blocked)
  • Backtesting settings toggles

Hardening pass

  • Fixed gates.py SyntaxError that blocked broker import/execution
  • Warm-up advances on realtime Data Analyst bars
  • Shadow intents still recorded when losing live priority
  • Idempotent shadow lots; budget row FOR UPDATE; stable LLM cache keys
  • Historical BT forces catchup for ai_strategy (no live LLM spend)
  • learn_enabled defaults true; re-enable resets warm-up episode

Documentation

Tests

tests/test_ai_strategy_slice{1,2,3,4}.py30 passed.

Deferred / next phases

  • Live outcome writes into trade_outcome_records
  • Shadow exit monitors (SL/TP/trail)
  • DB-unique daily BT cadence keys
  • Persist LLM call counts across restart
  • Auto-promote, walk-forward, multi-asset, config-backup/ACL expansion
Open in Web Open in Cursor 

anomaddev and others added 21 commits July 21, 2026 23:06
Update AI Strategy Branch with current commits
Wire ai_strategy preset card, thin forex-only builder with guidance/lookback params, promote API + list phase chips, and StrategyParams ai/signal types.

Co-authored-by: anomaddev <anomaddev@gmail.com>
Add ai_strategy preset with fail-closed stub evaluator, params.ai schema
persistence, isolated shadow intent/lot tables, ET warm-up lifecycle with
promote API, LLM budget reserve/settle at analyze_with_model, research
guidance materialization, and priority policy so warming AI cannot starve
live strategies.

Co-authored-by: anomaddev <anomaddev@gmail.com>
…sions

Replace the fail-closed stub with an async ModelSignalRuntime that resolves
model_id, injects research guidance as bias-only context, calls analyze_with_model
behind the spend gate, and maps structured Decision JSON to StrategyResult.
run_strategy_analysis is now async and awaits evaluate_async when present.

Co-authored-by: anomaddev <anomaddev@gmail.com>
Add strategy_memory_digests + learning_jobs, queue/run learning jobs from
trade outcomes (wins and losses, never per-close LLM), hook shadow close to
enqueue when learn_enabled/threshold met, inject digests into ModelSignalRuntime,
and fill load_weekly_bot_results from summarize_week.

Co-authored-by: anomaddev <anomaddev@gmail.com>
Register a deterministic compiled_playbook signal, queue ET-cadenced
daily backtests from strategy memory digests, and fork Auto AI feedback
to append learning notes instead of EMA builder suggestions.

Co-authored-by: anomaddev <anomaddev@gmail.com>
Add docs/strategies/ai-strategy.md and refresh README, params schema,
architecture notes, and config.env.example for warm-up/shadow/promote,
daily compiled backtests, and BROKERAI_LLM_KILL_SWITCH.

Co-authored-by: anomaddev <anomaddev@gmail.com>
Co-authored-by: anomaddev <anomaddev@gmail.com>
Fix gates.py SyntaxError that blocked all broker execution. Wire warm-up
advancement on realtime analysis, shadow intents that lose live priority,
idempotent shadow lots, learning job drain, LLM call caps, budget row
locks, and stable cache keys. Unlock builder model/LLM/learn controls and
default learn_enabled so daily improve can run.

Co-authored-by: anomaddev <anomaddev@gmail.com>
List provider catalog models with model_name persistence, add control tooltips, step lookback by 5, and stop wiping the DB on every dev.sh run.

Co-authored-by: Cursor <cursoragent@cursor.com>
Detect mismatched Settings → Reports toggles, offer to turn them on with defaults, and point users to configure run times.

Co-authored-by: Cursor <cursoragent@cursor.com>
Enqueue a durable job that waits for required reports, seeds a research digest, runs configurable improve loops, and expose Settings → AI Strategies plus list status.

Co-authored-by: Cursor <cursoragent@cursor.com>
First improve loop explores patterns without fills; later loops trade live-parity and learn only from prior digests. Reclaim secretary-orphaned running backtests so startup no longer sticks at 0%, and add cancel/progress polish on the Log page.

Co-authored-by: Cursor <cursoragent@cursor.com>
Conditional stand-aside anti-rules no longer kill-switch the whole book, and API/secretary drain is idempotent so a 3-loop startup queues one explore plus two trades—not six parallel backtests.

Co-authored-by: Cursor <cursoragent@cursor.com>
Claim feedback once per run, wait instead of skipping when a reservation is open, skip auto-analyze for startup origin, and reclaim expired LLM holds before new calls.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Exclusive worker leases plus unique action sequences stop overlapping writers; digest merges and playbook compile now honor lessons so trade loops stop cloning identical P/L.

Co-authored-by: Cursor <cursoragent@cursor.com>
ON CONFLICT ON CONSTRAINT failed on existing DBs that only have the unique index from ensure_indexes().

Co-authored-by: Cursor <cursoragent@cursor.com>
HTF bias extras like H4 were winning shared close-time ties and labeling bot status as 4H even when strategies analyze M15.

Co-authored-by: Cursor <cursoragent@cursor.com>
Also make instrument exposure upserts race-safe so concurrent syncs no longer take Secretary into UniqueViolation errors.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants