Skip to content

perf(agents): lazy package __init__ so one agent doesn't load the whole family#516

Merged
VforVitorio merged 1 commit into
devfrom
perf/lazy-agents-init
Jul 20, 2026
Merged

perf(agents): lazy package __init__ so one agent doesn't load the whole family#516
VforVitorio merged 1 commit into
devfrom
perf/lazy-agents-init

Conversation

@VforVitorio

Copy link
Copy Markdown
Owner

What

The Model Lab (and any single-agent caller) triggered loading the entire agent family because src/agents/__init__.py eagerly imported every agent, including the radio NLP stack (Whisper/RoBERTa/SetFit/NER) and the RAG embedder. So a Pace (XGBoost) query pulled seconds of model loading and VRAM it never needed.

Fix

Resolve the public names lazily via module __getattr__ (PEP 562). Importing a single agent (from src.agents.pace_agent import ... or from src.agents import run_pace_agent) now loads only that agent. The public surface, __all__, and direct submodule imports are unchanged; a full orchestrator run still loads what it uses.

Verified

  • from src.agents.pace_agent import run_pace_agent_from_state + from src.agents import run_pace_agent load NO NLP (no roberta/setfit/bert/sentence-transformer).
  • from src.agents import run_radio_agent, RadioMessage, RCMEvent still resolves and loads its stack.
  • A backend lap-state + agent data check stays GP-scoped with no NaN (no behaviour change).

…le family

The package __init__ eagerly imported every agent, so importing ANY of them (e.g. the Model Lab asking only for the Pace XGBoost model) loaded the radio NLP stack and the RAG embedder into memory and VRAM. Resolve each public name lazily via module __getattr__ (PEP 562): a single-agent call now loads only that agent, while the public surface and direct submodule imports are unchanged. Verified: importing pace loads no NLP; importing radio still resolves and loads its stack.
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 96e597b3-6d89-4d53-9371-7bc0bdc34203

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/lazy-agents-init

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the area: codebase Touches src/, scripts/, or notebooks/ label Jul 20, 2026
@VforVitorio
VforVitorio merged commit 509dba2 into dev Jul 20, 2026
13 checks passed
@VforVitorio
VforVitorio deleted the perf/lazy-agents-init branch July 20, 2026 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: codebase Touches src/, scripts/, or notebooks/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant