Archived context note: this document is historical planning material.
Canonical operational guidance lives inREADME.md,CONTRIBUTING.md,alphaswarm_docs/index.md, andalphaswarm_docs/operations/*. Seealphaswarm_docs/archive/README.md.
AlphaSwarm Refactor Master Prompt
Use this prompt with a coding model to implement the refactor program described in the report, but grounded in the current AlphaSwarm codebase and hard rules.
Copy/Paste Prompt
You are the principal refactor engineer for alphaswarm (AlphaSwarm).
Your task is to deliver an additive, zero-drift refactor that achieves these objectives:
- Onboard open-source agent, multi-agent, and automation components and expose them for interactive use and as components in orchestrations and strategies.
- Enhance the existing AlphaSwarm agentic framework and supporting infrastructure to enable iterative development of solutions similar to the included inspiration projects.
- Add high-leverage abstraction and metaclass/factory patterns for safe extensibility.
You must execute this as production-grade engineering, not conceptual design.
Inputs and inspiration context
- Core repo:
alphaswarm - Inspiration repos:
inspiration/TradingAgents-maininspiration/valuecell-maininspiration/FinRobot-masterinspiration/FinRL-Trading-masterinspiration/langflow-main
- External patterns already validated: CrewAI process modes, LangGraph StateGraph control flow, IAF strategy/deployment abstractions, daily_stock_analysis scheduler workflows, Orallexa-style fusion and bias tracking.
Non-negotiable AlphaSwarm hard rules
Do not violate any of these:
- All LLM calls must route through
alphaswarm/llm/providers/router.py::router_complete. - Agents must not read Postgres/Iceberg directly; agent reads go through DataMCP tools.
- Iceberg writes must go through
alphaswarm/data/iceberg_catalog.pywrapper entry points. - Runtime progress events must use
alphaswarm/tasks/_progress.pycontract. - Config reads must use
from alphaswarm.config import settings(no directos.environreads in service code). - Spec versions are immutable and hash-locked; never mutate existing version rows.
- Keep kill-switch and halt semantics intact and stronger, never weaker.
- No unsafe dynamic
exec/evalpatterns for user or model-supplied code. - Keep all existing behavior backward-compatible via additive paths and feature flags.
Existing architecture anchors (must extend, not replace)
- Orchestration:
alphaswarm/agents/graph/builder.pyalphaswarm/agents/graph/dialectical.pyalphaswarm/agents/graph/conditions.pyalphaswarm/agents/graph/state.py
- Runtime/spec lifecycle:
alphaswarm/agents/runtime.pyalphaswarm/agents/spec.pyalphaswarm/agents/registry.py
- Data boundary:
alphaswarm/agents/tools/data_mcp_bridge.pyalphaswarm/data/mcp/base.pyalphaswarm/data/mcp/registry.pyalphaswarm/data/mcp/tools/
- API/tasks/telemetry:
alphaswarm/api/routes/agent_specs.pyalphaswarm/api/routes/agents.pyalphaswarm/tasks/agent_tasks.pyalphaswarm/tasks/agent_watchdog_tasks.pyalphaswarm/agents/observability.py
- Kill/halt:
alphaswarm_client/src/components/common/KillSwitch.tsx- halt endpoints under
alphaswarm/api/routes/
- Existing abstraction patterns to mirror:
alphaswarm/core/registry.pyalphaswarm/rl/core/base.py(metaclass registration pattern)alphaswarm/kubernetes/protocol.py(adapter protocol + registration style)
Target architecture to implement
Build an additive orchestration control plane with these layers:
- Workflow spec layer (versioned, immutable, hash-locked, backward-compatible).
- Adapter registry layer (pluggable orchestration and strategy components).
- Graph orchestration runtime layer (LangGraph-first with deterministic fallback).
- Debate/fusion layer (bounded dialectical reasoning + weighted synthesis).
- Interactive workflow development surface (API + UI + replay).
- Safety envelope (kill switch, policy checks, cancellation, watchdog integration).
Architecture shape:
Required adapters (first-class components)
Implement these as adapter abstractions (not hardcoded one-offs):
LangGraphAdapter: standard graph execution and node transition hooks.CrewProcessAdapter: sequential/hierarchical crew mode interoperability.DialecticalDebateAdapter: Bull/Bear and multi-role adversarial debate loops.SignalFusionAdapter: deterministic fusion of quantitative and qualitative outputs.WeightCentricExecutionAdapter: FinRL/weight-centric bridge into AlphaSwarm execution.AutomationScheduleAdapter: periodic ingestion and agent run scheduling.WorkflowStudioAdapter: interactive graph/workflow build/run/inspect lifecycle.
Adapters must self-register through a metaclass/decorator pattern consistent with AlphaSwarm registry conventions.
Mandatory implementation phases
Phase 0 - Baseline protection and migration scaffolding
Implement:
- Add feature flags for all new major surfaces (workflow studio, crew adapter, fusion runtime, schedule adapter).
- Add compatibility shims so existing
build_full_pipeline_graphand current trader/research flows keep working unchanged. - Add explicit migration notes and rollback toggles.
Touchpoints:
alphaswarm/config/settings.pyalphaswarm/agents/graph/builder.pyalphaswarm/api/routes/agent_specs.py- docs updates under
alphaswarm_docs/
Acceptance criteria:
- Existing agent routes and tasks behave the same with all new flags disabled.
- New code paths are additive and opt-in.
Phase 1 - Orchestration abstraction and metaclass registry
Implement:
- Create a new orchestration abstraction package under
alphaswarm/agents/orchestration/with:- protocol/base interfaces,
- metaclass or decorator-based auto-registration,
- adapter lookup APIs.
- Register adapters by alias and type, following AlphaSwarm registry patterns.
- Add typed orchestration state contracts that extend existing graph state safely.
Touchpoints:
alphaswarm/agents/orchestration/(new package)alphaswarm/agents/graph/state.pyalphaswarm/core/registry.py(if needed for new kind categories)alphaswarm/agents/registry.py(for workflow spec loading/versioning linkage)
Acceptance criteria:
- Adapters are discoverable by alias and kind.
- New adapter can be plugged without modifying central switch statements.
Phase 2 - Graph-first runtime and bounded debate integration
Implement:
- Add a graph orchestration runtime that composes existing agent specs through adapters.
- Extend debate support with bounded rounds, explicit judge synthesis, and guardrail-enforced termination.
- Add node-level observability hooks (latency, token usage, tool usage, branch decisions).
- Add cooperative cancellation checks before node transitions.
Touchpoints:
alphaswarm/agents/graph/builder.pyalphaswarm/agents/graph/dialectical.pyalphaswarm/agents/graph/conditions.pyalphaswarm/agents/runtime.pyalphaswarm/agents/observability.py
Acceptance criteria:
- Debate loops cannot run unbounded.
- Every node transition is traceable.
- Halt signal interrupts graph progression safely.
Phase 3 - DataMCP-first ingestion and automation scheduling adapters
Implement:
- Add scheduler-driven ingestion orchestration inspired by daily_stock_analysis, but through AlphaSwarm task and DataMCP boundaries.
- Add new DataMCP tools where required for:
- news/market context ingestion status,
- orchestration run context retrieval,
- fusion input introspection.
- Ensure policy checks and tenancy boundaries are preserved.
Touchpoints:
alphaswarm/data/mcp/tools/(new tool modules)alphaswarm/data/mcp/registry.pyalphaswarm/agents/tools/data_mcp_bridge.pyalphaswarm/tasks/agent_tasks.pyalphaswarm/tasks/(new scheduler/automation task module if needed)
Acceptance criteria:
- No agent body directly imports ORM/Iceberg internals.
- New reads/writes are policy-gated through DataMCP and existing write wrappers.
Phase 4 - Signal fusion and weight-centric execution bridge
Implement:
- Add a deterministic fusion contract for combining:
- debate outputs,
- model predictions,
- risk overlays.
- Integrate weight-centric output path compatible with AlphaSwarm runtime and risk controls.
- Ensure final execution proposals route through existing risk and runtime gates.
Touchpoints:
alphaswarm/agents/trading/(new fusion modules or extension points)alphaswarm/agents/graph/(fusion node integration)alphaswarm/rl/portfolio/pipeline.py(integration point only if compatible and additive)alphaswarm/risk/interfaces as needed
Acceptance criteria:
- Fusion output is typed, reproducible, and logged.
- Risk gate can veto execution deterministically.
Phase 5 - Interactive workflow studio and immutable workflow versioning
Implement:
- Add interactive workflow APIs for create/read/version/run/replay workflows.
- Persist workflow specs with immutable version snapshots (same philosophy as existing
*_spec_versions). - Add lightweight UI integration points for workflow build/run/inspect (reuse current frontend patterns).
- Include run-level provenance: workflow version id, adapter versions, config hash.
Touchpoints:
alphaswarm/api/routes/(new workflow route module)- persistence models and migration(s) under
alphaswarm/persistence/+alembic/versions/ alphaswarm_client/src/routes/and/oralphaswarm_client/src/components/for workflow studio surfaces- docs updates in
alphaswarm_docs/
Acceptance criteria:
- Workflow runs are replayable by version id.
- UI can inspect run status and decision path without direct DB access.
Phase 6 - Kill switch, halt fan-out, watchdog hardening
Implement:
- Ensure every long-running orchestration run can be halted from existing global kill paths.
- Add halt propagation into orchestration runtime (graph edges and adapter execution loops).
- Integrate watchdog checks for stalled orchestration runs.
Touchpoints:
alphaswarm/api/routes/agent_specs.pyalphaswarm/tasks/agent_watchdog_tasks.pyalphaswarm/agents/graph/conditions.pyalphaswarm_client/src/components/common/KillSwitch.tsx
Acceptance criteria:
- Halt from UI/API stops active orchestration safely and updates run status coherently.
- Stalled runs are detectable and recoverable.
Cross-project pattern import rules
Import these patterns only through AlphaSwarm-safe boundaries:
- TradingAgents: bounded bull/bear debate plus manager adjudication.
- ValueCell: async orchestration and event routing for durable streaming updates.
- FinRobot: role specialization and manager/worker decomposition.
- FinRL-Trading: weight-centric contracts and risk-aware execution overlays.
- Langflow: interactive graph editing and workflow versioning ideas.
Do not import these anti-patterns:
- direct provider SDK LLM calls,
- unrestricted tool execution,
- mutable in-place workflow/spec rewriting,
- unconstrained dynamic code execution from user prompts,
- direct DB access from agent bodies.
Testing and validation matrix (required)
Add/update tests for:
- adapter registration and lookup,
- orchestration graph happy path and failure path,
- bounded debate termination behavior,
- cancellation and halt behavior,
- DataMCP policy enforcement for new tools,
- workflow version immutability and replay correctness,
- backward compatibility of legacy routes with flags disabled.
Minimum suites:
- unit tests for adapters/registry/state transitions,
- integration tests for API->task->runtime flow,
- regression tests for existing trader/research flows,
- watchdog/halt tests for stalled runs,
- telemetry shape tests for node-level spans and progress frames.
Documentation updates (required)
Update these docs (additive):
alphaswarm_docs/multi-agent-patterns.mdalphaswarm_docs/agentic-development.mdalphaswarm_docs/data-mcp.md- new doc:
alphaswarm_docs/workflow-studio.md(or equivalent) - any affected architecture index references in
alphaswarm_docs/index.md
Deliverable contract
Deliver work as a phased set of small reviewable PR-sized chunks:
- Abstractions + registry scaffolding.
- Runtime graph/debate integration.
- DataMCP and scheduler integration.
- Fusion + execution bridge.
- Workflow studio APIs + persistence + migrations.
- Frontend workflow controls + halt/watchdog reinforcement.
- Docs + final integration and regression pass.
For each chunk provide:
- changed files list,
- rationale and migration notes,
- feature flags added,
- tests added/updated,
- known risks and rollback step.
Output format for your implementation responses
For each phase, respond with:
Phase SummaryFiles Added/ChangedBehavioral ChangesSafety/Compatibility NotesTest EvidenceNext Phase Checklist
Do not skip tests, docs, or rollback notes.
Completion definition
The refactor is complete only when:
- all three objectives are explicitly met,
- existing AlphaSwarm behavior remains backward-compatible by default,
- new orchestration and workflow capabilities are additive and versioned,
- halt/kill safety works end-to-end,
- test and docs coverage is updated for all new surfaces.
Objective traceability:
- Objective 1 (onboard OSS agent/multi-agent/automation components):
- covered by Phases 1, 2, 3, and 4 via adapter registry, graph orchestration, scheduler integration, and fusion/execution bridge.
- Objective 2 (iterative development infrastructure):
- covered by Phases 0, 5, and 6 via feature flags, workflow studio/versioning, replay, halt/watchdog hardening.
- Objective 3 (abstraction/metaclass/factory emphasis):
- covered by Phases 1 and 5 via metaclass/decorator self-registration, typed contracts, immutable versioned workflow specs.