Sub-agent DB Query Performance: Batch Script vs CLI Iteration

Source type: obs · Harvested: 2026-05-02 · Original date: 2026-05-02T01:50:52.685Z Metadata: {"project":"lunhsiangyuan","type":"discovery","obs_id":64884}


obs/64884 · discovery · 2026-05-02T01:50:52.685Z

Sub-agent DB Query Performance: Batch Script vs CLI Iteration

Documented performance optimization pattern for sub-agent database analysis workflows. The ADC target classification task revealed significant inefficiency: executing 76 individual sqlite3 CLI commands resulted in 589-second execution time, despite each query completing in under 100ms. The true bottleneck was the cumulative overhead of 76 API round-trips, each requiring model inference and permission validation.

The optimization prescribes modifying spawn prompts to explicitly instruct agents: write a single Python script using the sqlite3 module that (a) extracts all required data, (b) performs in-memory classification/computation, and (c) outputs results to the output/ directory. This batching approach targets ≤5 tool calls total, with projected execution time reduction from 10 minutes to 1-2 minutes.

Implementation guidance allows 1-2 exploratory CLI calls for schema discovery in genuinely exploratory tasks, but mandates script-based execution once schema is understood. For classification tasks requiring pattern matching, the prompt should include known drug-target mappings upfront rather than forcing agent discovery.

Concepts: [“gotcha”,“pattern”,“trade-off”]

Facts: [“adc-target-classification agent executed 76 separate sqlite3 CLI tool calls over 589 seconds (~10 minutes)”,“Performance bottleneck is API round-trip + model inference + permission check overhead, not database query time (each query < 100ms)”,“Optimization strategy: spawn prompt should instruct agents to write single Python script using sqlite3 module for all queries, classification, and output generation”,“Expected improvement: 76 tool calls → 3-5 calls, 10 minutes → 1-2 minutes execution time”,“Schema exploration (1-2 CLI calls) acceptable, but main analysis work must converge to single script execution”]



[← 回 Alfred Brain Hub]