Building a Research Agent with a Search API
A pattern for an agent that plans queries, fetches results, and synthesizes a cited answer.
How it works
A research agent typically runs a plan-search-synthesize loop rather than a single search call: it first breaks the user's question into sub-questions, issues a search for each, optionally fetches full page content for the most promising results, and then composes a final answer that cites which sub-finding came from which source. The loop can iterate — if the first round of searches doesn't yield enough to answer confidently, the agent generates follow-up queries before synthesizing.
Example
Question: 'How has cloud GPU pricing changed in the last year?' The agent plans two sub-queries — cloud GPU pricing trends 2025 2026 and AWS Azure GCP GPU instance price changes — runs both, reads the top few snippets from each, and produces a synthesized answer with inline citations like [1] and [2] mapped to the source URLs.
A concrete example: SerpStack works well here because its response is already clean JSON — organic results, titles, snippets, and URLs — with no HTML parsing step standing between the API call and the prompt you hand the model.
Pitfalls
- Letting the agent plan unlimited sub-queries can spiral into a slow, expensive chain of searches for a question that needed only one; capping sub-query count per task is usually necessary.
- Synthesis quality drops sharply if the agent is allowed to cite a source it never actually retrieved content from — citation generation needs to be grounded strictly in fetched results, not the model's memory of similar-sounding sources.
- Sub-questions that are too similar to each other waste search budget on redundant results instead of covering the topic's actual breadth.