Agent, three different URL constructions.
Prerequisites
- Python 3.10+
OPENAI_API_KEYEXA_API_KEY— free from dashboard.exa.ai
Build it
1
Install and set both keys
2
Build the URL from the environment
3
Write a prompt that makes it cite
A search tool does not by itself produce sourced answers. This is the prompt that does:The last sentence matters most. Fabricated URLs are the characteristic failure of search agents, and they are far more convincing than a fabricated fact.
4
Create the agent
max_loops=2 gives the model room to search, read what came back, and then answer.5
Run a query that requires recency
The complete script
Keeping the key out of the URL
If embedding a secret in a URL makes you uncomfortable — and it should, given how often URLs end up in logs — the same key can be sent as a Bearer token on servers that accept one:env: prefix tells swarms to read the value from the environment at connection time, so the secret never appears in your source. See authentication patterns for every shape, including custom headers and OAuth.
Cost control
Search calls are billed per request, and an agent left to its own devices will happily run six searches where two would do.Next
- Firecrawl — once search finds the page, scrape it properly.
- Exa via swarms-tools — the same API as a plain Python tool, without MCP.