Saltar al contenido principal

Agents

This document covers the spec-driven agent surface added by the agentic-RAG expansion. The legacy CrewAI research crew (under alphaswarm/agents/crew.py) coexists with the new runtime; both register routes under /agents/* in the FastAPI gateway.

Concepts

  • AgentSpec — declarative blueprint (Pydantic). Holds role, system_prompt, tools, model, memory, RAG clauses, guardrails, output_schema, cost / call caps, and annotations. Defined in alphaswarm/agents/spec.py.
  • AgentRuntime — executor that turns a spec into a real run with full telemetry. Defined in alphaswarm/agents/runtime.py.
  • Registry — process-wide name → AgentSpec map. Discovered built-ins are registered at import time; YAML files under configs/agents/ are auto-loaded on first lookup. Declared in alphaswarm/agents/registry.py.
  • Reproducibility — every spec is hash-locked and snapshotted into agent_spec_versions on first use. Every run records a spec_version_id so it can be deterministically replayed.

The four teams

TeamSpecsPage
Researchresearch.news_miner, research.equity, research.universealphaswarm_docs/research-agents.md
Selectionselection.stock_selectoralphaswarm_docs/selection-agents.md
Tradertrader.signal_emitteralphaswarm_docs/trader-agents.md
Analysisanalysis.step, analysis.run, analysis.portfolio (+ reflector)alphaswarm_docs/analysis-agents.md

Inspiration-rehydration personas (Phase 2026-04-29)

Nine new spec-driven agents added by the rehydration. Each ships as a YAML in configs/agents/ and uses one or more of the new analytics tools in alphaswarm/agents/tools/analytics_tools.py.

Spec nameRoleTools
research.regime_analystADX trend/range gateregime_classifier_tool, historical_volatility
research.composite_voterTradFi-style indicator consensusmulti_indicator_vote_tool
research.basis_momentum_analystCommodity basis screeningfactor_screen_tool, realised_vol_tool
research.cointegration_analystPair stat-arbcointegration_tool, historical_volatility
research.intraday_momentum_analystGao 2018 intraday playsrealised_vol_tool, regime_classifier_tool
selection.cross_asset_skew_screenerCross-asset skew factorfactor_screen_tool
analysis.queue_position_analystHFT metric explainerhft_metrics_tool
analysis.cointegration_basket_finderUniverse-wide pair searchcointegration_tool
research.options_greeks_explainerBachelier + inverse Greeksoption_greeks_tool, option_spread_tool

Composite pipeline: see alphaswarm/agents/graph/builder.py::build_quant_research_pipeline_graph which chains composite_voter → regime_analyst → cointegration_analyst → risk_simulator → emit_signal_event/reject_decision_log with the existing risk-simulator approval gate.

Run lifecycle

Persistence

TablePurpose
agent_specsLogical agent (latest version pointer)
agent_spec_versionsImmutable hash-locked spec snapshot
agent_runs_v2One row per run
agent_run_stepsOne row per step (LLM / tool / RAG / memory / guardrail)
agent_run_artifactsSidecar artifacts referenced by a run
agent_evaluations + agent_eval_metricsEval harness results
agent_annotationsUser/agent annotations for optimisation

REST surface

GET  /agents/specs                              — list registered specs
GET /agents/specs/{name} — spec detail (full payload)
GET /agents/specs/{name}/versions — version history
POST /agents/runs/v2/sync — synchronous run
GET /agents/runs/v2 — list runs (filter by spec/status)
GET /agents/runs/v2/{id} — full trace incl. steps
POST /agents/runs/v2/{id}/replay — replay against snapshotted spec
GET /agents/evaluations — list eval reports

Guardrails

AgentSpec.guardrails (parsed by AgentRuntime._guardrail_check):

  • cost_budget_usd — hard ceiling per run (raises GuardrailViolation).
  • rate_limit_per_minute — TODO: enforced at the call site.
  • max_calls — caps the number of LLM round-trips per run.
  • forbidden_terms — strings that must not appear in the output.
  • require_rationale — output must include a rationale-style key.
  • min_confidence — output's confidence field must clear this floor.

Don'ts

  • Don't bypass AgentRuntime.run for spec-driven agents — telemetry, guardrails, cost caps, and agent_runs_v2 rely on it.
  • Don't mutate agent_spec_versions rows — they are immutable.
  • Don't write a new spec without registering it (decorator or YAML); the LangGraph builders look up by name and will skip unknown specs.