The WebSearchSkill provides agents with the ability to search the internet using the Brave Search API. This allows agents to access real-time information and up-to-date facts.
The WebSearchSkill implements the Skill protocol and provides a web_search tool. It handles the communication with Brave's API and formats the results into a human-readable (and LLM-readable) text format.
To use this skill, you need a Brave Search API key. You can provide the key in two ways:
- Constructor Parameter: Pass the key when instantiating the skill.
- Environment Variable: Set the
BRAVE_API_KEYenvironment variable.
If no key is provided via either method, the constructor will raise a ValueError.
Install the skill using the SkillManager.
from ecs_agent import SkillManager
from ecs_agent.skills.web_search import WebSearchSkill
manager = SkillManager()
search_skill = WebSearchSkill(api_key="your-brave-api-key")
manager.install(world, agent_entity, search_skill)Once installed, the LLM can call the web_search tool like any other tool.
# The tool call generated by the LLM
tool_call = ToolCall(
id="call_123",
name="web_search",
arguments={"query": "latest news about SpaceX Starship", "count": 5}
)The tool returns a formatted string containing the titles, URLs, and snippets of the search results.
Example Output:
1. Starship | SpaceX
https://www.spacex.com/vehicles/starship/
SpaceX's Starship spacecraft and Super Heavy rocket represent a fully reusable transportation system...
2. SpaceX Starship - Wikipedia
https://en.wikipedia.org/wiki/SpaceX_Starship
Starship is a fully reusable, super heavy-lift launch vehicle under development by SpaceX...
- Endpoint:
GET https://api.search.brave.com/res/v1/web/search - Authentication: Uses the
X-Subscription-Tokenheader. - Parameters:
q: The search query (string, required).count: Number of results to return (integer, default 10).
- Format: The skill requests
application/jsonbut returns a formatted text summary to the agent to minimize token overhead and improve readability.