OpenSaC: A Python Library for Search as Code in Deep Research Agents

Qi Liu, Jiaxin Mao, Fengbin Zhu, Tat-Seng Chua, Ji-Rong WenarXiv 2026

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:

  1. High Latency: Each search requires a full round-trip of model reasoning.
  2. Context Bloat: Returning every intermediate search result to the model quickly fills the context window with irrelevant noise.
  3. 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, and llm.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.
Comparison between traditional tool-calling and the Search as Code paradigm.

Datasets

The authors evaluated OpenSaC using two primary benchmarks:

  1. BrowseComp: A benchmark focused on challenging fact-finding tasks.
  2. 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.
Figure 2: Program composition and provider dispatch in OpenSaC. fuse runs locally, while provider-backed capabilities use a shared runtime for concurrency, dispatch, lifecycle management, and tracing. Adapter choices illustrate extensibility: Tavily, Qwen3 Rerank, Jina Rerank, and Crawl4AI require extensions, while OpenRouter is an OpenAI-compatible endpoint. Custom adapters use Python entry points. The program is schematic; Listings 1 and 2 show recorded case-study programs (Section 3.3).

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.
Table 2: Native retrieval and OpenSaC on BrowseComp and WideSearch. Quality is accuracy or macro row F1, respec- tively; time, tokens, and recorded model cost are per-task means. Failed runs and cached input tokens are included.

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

Abstract

Deep research agents investigate complex questions through iterative search, source examination, and evidence synthesis. A conventional workflow alternates reasoning with individual search and reading actions. Search as Code introduces a new paradigm: agents write programs that compose search, source reading, reranking, model calls, and local processing, returning selected observations for further reasoning. To support this workflow in existing coding agents, we present OpenSaC, an open-source Python library with a companion Search as Code skill. Configurable capability interfaces let agents combine these operations while retaining evidence for inspection and reuse. Compared with standard Codex using its built-in web search, the OpenSaC configuration uses less execution time and fewer model tokens on BrowseComp and WideSearch, with higher accuracy on BrowseComp and slightly lower row F1 on WideSearch. We aim to lower the barrier to adopting Search as Code and provide an open foundation for community development and transparent research on deep research agents.
BibTeX
@misc{liu2026opensac,
  author = {Qi Liu and Jiaxin Mao and Fengbin Zhu and Tat-Seng Chua and Ji-Rong Wen},
  title = {{OpenSaC: A Python Library for Search as Code in Deep Research Agents}},
  year = {2026},
  eprint = {2610.25779},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2610.25779},
}
Figure