TradingAgents/tradingagents
ahmet guzererler 728ae69eab
feat: PM brain upgrade — macro/micro agents & memory split (#123)
* feat: introduce flow_id with timestamp-based report versioning

Replace run_id with flow_id as the primary grouping concept (one flow =
one user analysis intent spanning scan + pipeline + portfolio). Reports
are now written as {timestamp}_{name}.json so load methods always return
the latest version by lexicographic sort, eliminating the latest.json
pointer pattern for new flows.

Key changes:
- report_paths.py: add generate_flow_id(), ts_now() (ms precision),
  flow_id kwarg on all path helpers; keep run_id / pointer helpers for
  backward compatibility
- ReportStore: dual-mode save/load — flow_id uses timestamped layout,
  run_id uses legacy runs/{id}/ layout with latest.json
- MongoReportStore: add flow_id field and index; run_id stays for compat
- DualReportStore: expose flow_id property
- store_factory: accept flow_id as primary param, run_id as alias
- runs.py / langgraph_engine.py: generate and thread flow_id through all
  trigger endpoints and run methods
- Tests: add flow_id coverage for all layers; 905 tests pass

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat: PM brain upgrade — macro/micro summary agents, memory split, forensic dashboard

Replaces the PM's raw-JSON context (~6,800 tokens on deep_think) with a
MAP-REDUCE compression layer using two parallel mid_think summary agents,
achieving ~70% cost reduction at the PM tier.

Architecture:
- MacroMemory: new regime-level memory class (MongoDB/JSON, separate from
  per-ticker reflexion memory) with record_macro_state/build_macro_context
- ReflexionMemory: extended with collection_name param to isolate
  micro_reflexion from the pipeline reflexion collection (with distinct
  local JSON fallback path to prevent file collision)
- Macro_Summary_Agent (mid_think): compresses scan_summary into a 1-page
  regime brief with memory injection; sentinel guard prevents LLM call on
  empty/error scan data ("NO DATA AVAILABLE - ABORT MACRO")
- Micro_Summary_Agent (mid_think): compresses holding_reviews + candidates
  into a markdown table brief with per-ticker memory injection
- Portfolio graph: parallel fan-out (prioritize_candidates → macro_summary
  ‖ micro_summary → make_pm_decision) using _last_value reducers for safe
  concurrent state writes (ADR-005 pattern)
- PM refactor: Pydantic PMDecisionSchema enforces Forensic Execution
  Dashboard output (macro_regime, forensic_report, per-trade
  macro_alignment/memory_note/position_sizing_logic); with_structured_output
  as primary path, extract_json fallback for non-conforming providers
- PM sentinel handling: "NO DATA AVAILABLE" in macro_brief substituted
  with actionable conservative guidance before LLM sees it

62 new unit tests across 4 test files covering all new components.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: address code review — relaxed error guard, ticker_analyses, PM memory wiring

1. macro_summary_agent: relaxed error guard to only abort when scan_summary's
   sole key is "error" (partial failures with real data are now processed)
2. micro_summary_agent: now reads ticker_analyses from state and enriches
   the per-ticker table with trading graph analysis data
3. portfolio_graph: wires macro_memory and micro_memory to PM factory call
4. test_empty_state: updated test for new partial-failure behavior

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-26 12:55:24 +01:00
..
agents feat: PM brain upgrade — macro/micro agents & memory split (#123) 2026-03-26 12:55:24 +01:00
dataflows Bolt: Optimize string building in yfinance_scanner.py (#114) 2026-03-26 09:33:06 +01:00
graph feat: PM brain upgrade — macro/micro agents & memory split (#123) 2026-03-26 12:55:24 +01:00
llm_clients merge: sync with upstream TauricResearch/TradingAgents v0.2.2 2026-03-23 12:17:25 +00:00
memory feat: PM brain upgrade — macro/micro agents & memory split (#123) 2026-03-26 12:55:24 +01:00
pipeline feat: include portfolio holdings in auto mode pipeline analysis (#104) 2026-03-24 18:35:53 +01:00
portfolio feat: PM brain upgrade — macro/micro agents & memory split (#123) 2026-03-26 12:55:24 +01:00
__init__.py fix: set process-level UTF-8 default for cross-platform consistency 2026-03-22 23:42:37 +00:00
api_usage.py Address code review: add debug logging for unknown method resolution 2026-03-21 17:27:38 +00:00
daily_digest.py feat: daily digest consolidation and Google NotebookLM sync (#23) 2026-03-19 12:21:03 +01:00
default_config.py feat: configurable max_auto_tickers + run persistence with phase-level node re-run (#109) 2026-03-25 15:27:28 +01:00
notebook_sync.py merge: resolve conflicts with origin/main (PR #85 merged) 2026-03-22 06:52:39 +00:00
observability.py Remove unused import `field` from `observability.py` (#120) 2026-03-26 11:17:58 +01:00
report_paths.py feat: load flow_id in FE to resume runs and fix max_tickers cap (#113) 2026-03-26 07:10:42 +01:00