Skip to content

Latest commit

 

History

History
70 lines (48 loc) · 2.32 KB

File metadata and controls

70 lines (48 loc) · 2.32 KB

Web Search Skill

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.

Overview

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.

Setup

API Key Management

To use this skill, you need a Brave Search API key. You can provide the key in two ways:

  1. Constructor Parameter: Pass the key when instantiating the skill.
  2. Environment Variable: Set the BRAVE_API_KEY environment variable.

If no key is provided via either method, the constructor will raise a ValueError.

Installation

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)

Usage Examples

Calling the Web Search Tool

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}
)

Handling Search Results

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...

Brave Search API Reference

  • Endpoint: GET https://api.search.brave.com/res/v1/web/search
  • Authentication: Uses the X-Subscription-Token header.
  • Parameters:
    • q: The search query (string, required).
    • count: Number of results to return (integer, default 10).
  • Format: The skill requests application/json but returns a formatted text summary to the agent to minimize token overhead and improve readability.