How avinash8891/agents-auto-research works
1. What this repo is
- agents-auto-research is an autonomous research loop for quantitative trading strategies.
- The system iterates over a thesis → compile → backtest → evaluate → learn cycle, currently centered on the ema and orb strategy families.
2. Top-level control flow
- autoresearch_controller.py is the main state machine and loop coordinator.
- It delegates round-level work to autoresearch_orchestration.py, which fans out into planning, research, compilation, and experiment evaluation.
- The outputs of one round become inputs to the next via saved state, trace artifacts, and database records.
3. Planning and thesis generation
- autoresearch_planning.py selects what to test next based on previous results and constraints.
- autoresearch_research.py drives per-thesis research and produces structured outputs that describe config changes, expected effects, and disqualifiers.
- research_conductor.py is the LLM-facing conductor that coordinates subagents and tool usage.
4. Agent layer
- research_subagents.py contains specialist agents such as analyst and web-research roles.
- agent_runners.py, agent_openai_calls.py, and agent_infra.py wrap OpenAI Agents SDK / API calls, retries, proxy handling, and usage accounting.
- This layer depends on the local openai-oauth proxy mentioned in the README, so agent execution is an external-service boundary.
5. Compiler / operationalization layer
- compiler_pipeline.py is the main orchestration point for turning a thesis into something runnable.
- compiler_builder.py, compiler_operationalize.py, and compiler_thesis_io.py generate, validate, and persist missing strategy primitives or config code.
- This plane is what bridges the research hypothesis into concrete strategy/runtime changes.
6. Strategy family boundary
- strategies/ defines the pluggable strategy families, with ema/ and orb/ as first-class examples and _demo/ as a scaffold.
- Each family exposes research descriptions, validation rules, defaults, prompts, signals, exits, and runner/contract/schema logic.
- strategy_family.py and strategies/base.py form the registration and abstraction boundary used by the rest of the system.
7. Backtest execution
- backtest/ is the simulation engine: data universe handling, resampling, filters, result schema, diagnostics, and the runner.
- Family-specific wrappers such as backtest_5ema.py, backtest_orb_v2.py, and strategies/orb/runner.py connect strategy configs to the shared engine.
- data_loader.py, analyst_dataframe_helpers.py, and numba_kernels.py support market data loading, analysis, and performance-critical computations.
8. Evaluation and metrics
- experiment_evaluator.py, eval_harness.py, eval_cli.py, and eval_metrics.py compute and report experiment outcomes.
- metrics.py, diagnostic_contracts.py, and backtest/event_diagnostics.py define the signals used to judge whether a thesis improved the strategy.
- Evaluation is a separate concern from raw backtesting: it interprets results in the context of the research loop.
9. Persistence and state
- backtest_run_db.py stores experiment records in SQLite; the test suite includes crash-consistency and timestamp coverage for that DB path.
- autoresearch_state.py, autoresearch_paths.py, and autoresearch_runtime_paths.py manage JSON/state-file locations for the active run.
- research_memory.py provides cross-session memory, while persistence_utils.py and artifact_io.py handle file serialization and artifact I/O.
10. Tracing, artifacts, and replayable evidence
- trace_sdk.py and the trace_* modules record agent and research events for later analysis.
- trace_adapters/ converts traces from specific improvement systems (halo, recursive_improve, reflexio) into the repo’s common format.
- runtime/, trace_exports/, and runtime/jobs/ hold persisted round artifacts, summaries, and trace exports that make runs auditable and replayable.
11. Self-improvement and reflection tooling
- improvement_halo.py, improvement_recursive_improve.py, improvement_reflexion.py, and related modules analyze traces and generate improvement suggestions.
- These modules do not run the strategy loop directly; they operate on the loop’s outputs to propose better prompts, tool order, or agent behavior.
- reflexio_agent_reflections.py and trace_improvement_report.py are part of this post-run learning pipeline.
12. Operational entry points
- autoresearch_cli.py is the local CLI for managing experiments.
- vps_runner.py deploys a chosen git ref over SSH to a remote host and launches the controller in a tmux session, making remote execution a first-class workflow.
- web_research_cli.py and scripts/ provide supporting operational tasks such as trace review, token audits, and environment setup.
13. Configuration and policy boundaries
- configs/ defines base strategy configs and variants used by the research loop and backtests.
- compiler_defaults.py, compiler_validate.py, orb_contract.py, strategies/*/validate.py, and strategies/validate_utils.py enforce which config changes are legal.
- thesis_validator.py, research_doctrine.py, and family_research_spec.py encode higher-level rules about what constitutes a valid research proposal.
14. External dependencies that matter architecturally
- Market data comes from a local filesystem root configured via AUTORESEARCH_DATA_ROOT.
- LLM/agent execution depends on the OpenAI proxy and SDK boundary.
- Remote orchestration depends on SSH access to a VPS, and optional run notifications can go to Discord webhooks.
15. How to draw the diagram
- The central loop is: controller/orchestration → conductor/subagents → compiler → backtest engine → evaluator → persistence/traces → next planning round.
- Around that loop sit the strategy-family plugins, configuration/schema validation, and the artifact/trace stores.
- A separate operational path handles VPS deployment and remote execution, while another side path consumes traces for improvement analysis.
Main entry points: autoresearch_controller.py Controller · compiler_pipeline.py Compiler · runner.py Backtest runner · autoresearch_planning.py Planning
Components 33
Core loop
Main autonomous research state machine and round orchestration.
- Controller · Main loop coordinator for the autonomous research cycle.
autoresearch_controller.py - Orchestration · Fans out round-level planning, research, compilation, and evaluation.
autoresearch_orchestration.py - Planning · Chooses what to test next from prior results and constraints.
autoresearch_planning.py - Research · Drives per-thesis research and structured research outputs.
autoresearch_research.py
Agent layer
LLM-facing research conductor and subagent/runtime wrappers.
- Conductor · Coordinates subagents, prompts, and tool use for research tasks.
research_conductor.py - Subagents · Specialist analyst and web-research roles used by the conductor.
research_subagents.py - Runners · Execution wrappers for agent tasks and retries.
agent_runners.py - OpenAI calls · OpenAI SDK/API integration and request handling.
agent_openai_calls.py
Compiler plane
Turns theses into runnable strategy/config changes.
- Compiler · Orchestrates operationalization of a thesis into runnable changes.
compiler_pipeline.py - Builder · Generates or fills in strategy primitives and config code.
compiler_builder.py - Operationalize · Bridges research hypotheses into concrete runtime changes.
compiler_operationalize.py
Strategy families
Pluggable strategy abstractions and concrete families.
- Strategy base · Common strategy interface and registration boundary.
strategies/base.py - Family registry · Strategy-family registration and selection used by the rest of the system.
strategy_family.py - EMA family · Concrete EMA strategy family with prompts, defaults, signals, and validation.
strategies/ema/strategy.py - ORB family · Concrete ORB strategy family with runner, schema, and validation.
strategies/orb/strategy.py
Backtest engine
Simulation, market data, and strategy execution support.
- Backtest runner · Executes the shared simulation engine for strategy experiments.
backtest/runner.py - Market data · Universe loading, resampling, filters, and data preparation.
backtest/data_universe.py
Evaluation
Interprets backtest outcomes and experiment quality.
Persistence
Run state, memory, and experiment storage.
- Run DB · Persistent experiment record store for backtest runs.
backtest_run_db.py - State file · JSON state for the active run and round progression.
autoresearch_state.py - Memory · Cross-session research memory and recalled context.
research_memory.py
Tracing & learning
Trace capture, exports, adapters, and post-run improvement.
- Trace SDK · Records research and agent events for later analysis.
trace_sdk.py - Trace adapters · Converts external improvement traces into the common format.
trace_adapters/__init__.py - Halo · Post-run improvement analysis based on trace evidence.
improvement_halo.py - Recursive improve · Trace-driven improvement suggestions and analysis.
improvement_recursive_improve.py - Reflexion · Reflection and improvement generation from traces.
improvement_reflexion.py
Operations
CLI, remote execution, and scripts for running the system.
- CLI · Local command-line entrypoint for managing experiments.
autoresearch_cli.py - VPS runner · Deploys a git ref over SSH and launches the controller remotely.
vps_runner.py
Policy & validation
Research rules, thesis constraints, and config validation.
- Doctrine · High-level rules for valid research proposals.
research_doctrine.py - Thesis validator · Validates thesis quality and constraints.
thesis_validator.py - Compiler validate · Validation rules for compiler-generated changes and configs.
compiler_validate.py - Validate utils · Shared validation helpers for strategy families.
strategies/validate_utils.py
Connections 37
- Controller → Orchestration: coordinates · Controller delegates round work to orchestration.
- Orchestration → Planning: plans next · Orchestration asks planning what to test next.
- Orchestration → Research: runs research · Orchestration dispatches thesis research.
- Research → Conductor: uses · Research execution is mediated by the LLM conductor.
- Conductor → Subagents: delegates · Conductor coordinates specialist roles.
- Conductor → Runners: executes via · Conductor uses agent runtime wrappers.
- Runners → OpenAI calls: calls · Runners wrap OpenAI API interactions.
- Research → Compiler: hands off · Research outputs feed compilation/operationalization.
- Compiler → Builder: builds · Compiler pipeline synthesizes missing strategy primitives.
- Compiler → Operationalize: applies · Pipeline bridges thesis into runnable changes.
- Compiler → Compiler validate: checks · Generated changes are validated before use.
- Compiler → Thesis validator: constrains · Thesis-level constraints gate compiler input.
- Family registry → Strategy base: extends · Family registry is built on the base strategy abstraction.
- Family registry → EMA family: registers · EMA is a first-class family.
- Family registry → ORB family: registers · ORB is a first-class family.
- EMA family → Validate utils: validates · EMA-specific validation uses shared helpers.
- ORB family → Validate utils: validates · ORB-specific validation uses shared helpers.
- Orchestration → Backtest runner: triggers · Research rounds culminate in backtest execution.
- Backtest runner → Market data: loads data · Runner depends on market data universe preparation.
- ORB family → Backtest runner: runs on · ORB family provides runner integration for the engine.
- Backtest runner → Evaluator: emits results · Simulation results flow into evaluation.
- Evaluator → Metrics: scores with · Evaluator relies on metrics and diagnostics.
- Backtest runner → Run DB: persists · Experiment runs are recorded in SQLite.
- Controller → State file: stores · Loop progression is persisted in run state.
- Controller → Memory: remembers · Cross-round and cross-session memory informs future rounds.
- Controller → Trace SDK: traces · Controller and research events are recorded for replay.
- Trace SDK → Trace adapters: imports · Adapters normalize external trace formats.
- Trace adapters → Halo: feeds · Imported traces support Halo analysis.
- Trace adapters → Recursive improve: feeds · Imported traces support recursive-improve analysis.
- Trace adapters → Reflexion: feeds · Imported traces support reflexion analysis.
- Halo → Planning: informs · Improvement outputs shape the next planning round.
- Recursive improve → Planning: informs · Trace-driven suggestions feed future planning.
- Reflexion → Planning: informs · Reflection outputs influence subsequent plans.
- CLI → Controller: starts · CLI launches the main controller loop.
- VPS runner → Controller: launches · Remote VPS execution starts the controller in tmux.
- Doctrine → Thesis validator: defines rules · Doctrine provides the higher-level research policy.
- Thesis validator → Planning: gates · Planning is constrained by thesis validity rules.