How to Add Web Search to an OpenAI Agents SDK Agent (No API Key)
How to Add Web Search to an OpenAI Agents SDK Agent (No API Key) An OpenAI Agents SDK agent can only answer from its model's training data until you give it a web search tool. openai-agents-agentsearch adds web search to an OpenAI Agents SDK agent as a plain function tool: live search that works free with no API key, plus paid tools for reading full pages and JavaScript-heavy sites. Because it is…
Adding web search capabilities to an OpenAI Agents SDK agent is now possible without requiring an API key. The openai-agents-agentsearch package provides three FunctionTool objects, one of which is the agentsearch_search tool for live web search. This tool offers a free tier with up to 25 searches per day per IP, and paid options for more extensive use. The package requires Python 3.10 or later and is compatible with OpenAI models.
To utilize the search tool, you call it through the on_invoke_tool method of the FunctionTool object using JSON formatted arguments. The tool returns the search results as a JSON string containing the title, URL, and content of the articles. If the search fails, the tool returns a string starting with "Error:". The tool never raises exceptions, allowing the agent to handle failures gracefully.
In a basic implementation, you create a search tool and pass it to the Agent constructor along with instructions for the agent to cite sources when answering questions. The tool is called when the agent needs to search the web, and the search results are returned as a JSON object. The agent can then use this information to provide more accurate and up-to-date answers. This setup allows the agent to leverage web search for current information without the need for an API key.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.