feat(agent): complete EvoAgent integration for all 6 agent roles

Migrate all agent roles from Legacy to EvoAgent architecture:
- fundamentals_analyst, technical_analyst, sentiment_analyst, valuation_analyst
- risk_manager, portfolio_manager

Key changes:
- EvoAgent now supports Portfolio Manager compatibility methods (_make_decision,
  get_decisions, get_portfolio_state, load_portfolio_state, update_portfolio)
- Add UnifiedAgentFactory for centralized agent creation
- ToolGuard with batch approval API and WebSocket broadcast
- Legacy agents marked deprecated (AnalystAgent, RiskAgent, PMAgent)
- Remove backend/agents/compat.py migration shim
- Add run_id alongside workspace_id for semantic clarity
- Complete integration test coverage (13 tests)
- All smoke tests passing for 6 agent roles

Constraint: Must maintain backward compatibility with existing run configs
Constraint: Memory support must work with EvoAgent (no fallback to Legacy)
Rejected: Separate PM implementation for EvoAgent | unified approach cleaner
Confidence: high
Scope-risk: broad
Directive: EVO_AGENT_IDS env var still respected but defaults to all roles
Not-tested: Kubernetes sandbox mode for skill execution
This commit is contained in:
2026-04-02 00:55:08 +08:00
parent 0fa413380c
commit 16b54d5ccc
73 changed files with 9454 additions and 904 deletions

View File

@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from pathlib import Path
from typer.testing import CliRunner
from backend import cli
@@ -126,6 +128,86 @@ def test_backtest_runs_full_market_store_prepare_before_start(monkeypatch, tmp_p
]
def test_live_cli_defaults_to_generic_run_label(monkeypatch, tmp_path):
project_root = tmp_path
(project_root / ".env").write_text("FINNHUB_API_KEY=test\n", encoding="utf-8")
calls = []
runner = CliRunner()
monkeypatch.setattr(cli, "get_project_root", lambda: project_root)
monkeypatch.setattr(cli, "handle_history_cleanup", lambda config_name, auto_clean=False: None)
monkeypatch.setattr(cli, "run_data_updater", lambda project_root: None)
monkeypatch.setattr(cli, "auto_update_market_store", lambda config_name, end_date=None: None)
monkeypatch.setattr(
cli,
"auto_enrich_market_store",
lambda config_name, end_date=None, lookback_days=120, force=False: None,
)
monkeypatch.setattr(cli.os, "chdir", lambda path: None)
def fake_run(cmd, check=True, **kwargs):
calls.append(cmd)
return 0
monkeypatch.setattr(cli.subprocess, "run", fake_run)
result = runner.invoke(cli.app, ["live", "--trigger-time", "now"])
assert result.exit_code == 0
assert calls
assert "--config-name" in calls[0]
config_index = calls[0].index("--config-name")
assert calls[0][config_index + 1] == "default_live_run"
def test_backtest_cli_defaults_to_generic_run_label(monkeypatch, tmp_path):
project_root = tmp_path
calls = []
runner = CliRunner()
monkeypatch.setattr(cli, "get_project_root", lambda: project_root)
monkeypatch.setattr(cli, "handle_history_cleanup", lambda config_name, auto_clean=False: None)
monkeypatch.setattr(cli, "run_data_updater", lambda project_root: None)
monkeypatch.setattr(
cli,
"auto_prepare_backtest_market_store",
lambda config_name, start_date, end_date: None,
)
monkeypatch.setattr(
cli,
"auto_enrich_market_store",
lambda config_name, end_date=None, lookback_days=120, force=False: None,
)
monkeypatch.setattr(cli.os, "chdir", lambda path: None)
def fake_run(cmd, check=True, **kwargs):
calls.append(cmd)
return 0
monkeypatch.setattr(cli.subprocess, "run", fake_run)
result = runner.invoke(
cli.app,
["backtest", "--start", "2026-03-01", "--end", "2026-03-10"],
)
assert result.exit_code == 0
assert calls
assert "--config-name" in calls[0]
config_index = calls[0].index("--config-name")
assert calls[0][config_index + 1] == "default_backtest_run"
def test_main_parser_defaults_to_generic_run_label():
from backend.main import build_arg_parser
parser = build_arg_parser()
args = parser.parse_args([])
assert args.config_name == "default_run"
def test_ingest_enrich_runs_batch_enrichment(monkeypatch):
calls = []