TL;DR
OpenSaC is an open-source Python library that implements the "Search as Code" (SaC) paradigm for deep research agents. By enabling agents to write and execute programs that batch searches and process evidence locally, OpenSaC reduces execution time by ~30% and token costs by up to ~38% compared to traditional step-by-step tool calling, all while maintaining or improving research quality.
What Problem Does This Paper Address?
Traditional research agents typically follow a "reasoning-action" loop (like ReAct), where the model performs one search, reads the result, reasons about it, and then decides on the next action. While effective for simple tasks, this approach is highly inefficient for complex research—such as comparing labor statistics across multiple states—where many information needs are known upfront.
This conventional workflow suffers from:
- High Latency: Each search requires a full round-trip of model reasoning.
- Context Bloat: Returning every intermediate search result to the model quickly fills the context window with irrelevant noise.
- High Cost: Frequent model calls and large contexts lead to significant API expenses.
The authors introduce OpenSaC to bring the "Search as Code" concept—originally proposed by Perplexity—into the open-source ecosystem, making it accessible for standard coding agents like Codex or Claude Code.
Methods
The core shift in OpenSaC is making an executable program the unit of interaction. Instead of calling a "Search" tool, the agent writes a Python script that uses the OpenSaC SDK to orchestrate its research.
Key components include:
- Composable SDK: A set of typed interfaces for
search,fetch,rerank, andllm.extract. It includes batch variants (e.g.,search.many) to handle multiple queries in parallel. - Local Processing: Agents can use standard Python (regex, JSON parsing, math) to filter, merge, and deduplicate data locally before returning only the most relevant observations to the reasoning model.
- Provider Dispatch: A modular adapter system allows the library to route requests to various backends (like Serper, Tavily, or Jina Reader) without changing the agent's code logic.
- Search as Code Skill: A companion set of instructions that guides the agent on when to batch requests and how to retain evidence for later reuse.
Datasets
The authors evaluated OpenSaC using two primary benchmarks:
- BrowseComp: A benchmark focused on challenging fact-finding tasks.
- WideSearch: A benchmark designed for broad information-seeking and evidence collection across multiple sources.
Evaluation was conducted using the Harbor framework, which provides a containerized environment for reproducible agent testing.
Key Insights and Ideas
- Efficiency through Batching: By grouping independent requests, agents can bypass multiple reasoning turns. For example, an agent can search for unemployment data for five different states in a single code execution rather than five separate turns.
- Evidence Selection: The "Search as Code" approach allows the agent to act as a data engineer. It can write code to extract a specific table row from a 50KB webpage, returning only a few bytes of crucial data to the LLM's context.
- Transparency and Inspectability: Because the research process is captured in a Python script, researchers can inspect exactly how an agent arrived at an answer, making the system more debuggable than "black-box" tool-calling loops.
- Decoupling Strategy from Execution: The LLM focuses on the high-level research strategy, while the Python runtime handles the heavy lifting of data retrieval, concurrency, and formatting.
Key Results
The researchers compared OpenSaC against a "Native" Codex environment with built-in web search. The quantitative gains were significant:
- Speed: OpenSaC reduced mean execution time by 30.3% on BrowseComp and 29.5% on WideSearch.
- Cost: Model token usage dropped by 37.8% on BrowseComp, leading to a 36.4% reduction in model costs.
- Quality: On BrowseComp, accuracy actually improved by 2.96 percentage points. On WideSearch, the quality remained stable, with only a negligible decline (0.84 points) in F1 score.
Limitations and Future Work
While OpenSaC shows clear benefits, the authors note several areas for improvement:
- Agent Proficiency: The system relies on the agent's ability to write bug-free Python. While coding agents are improving, they still require robust "skill" guidance to use SaC effectively.
- Error Recovery: Future work could involve specialized fine-tuning or reinforcement learning to help agents better handle API failures or execution errors within their generated programs.
- Provider Reliability: The quality of the research is ultimately capped by the underlying search and fetching services. Expanding source coverage and improving the relevance of fetched snippets remains a priority.
Summary updated