org.llm4s.toolapi.builtin.search
Search tools for web searches and lookups.
These tools provide web search capabilities using various search engines. All search tools follow the "config at the edge" pattern where configuration is loaded at the application boundary via org.llm4s.config.Llm4sConfig and passed to the tool's create() method.
== Available Tools ==
-
DuckDuckGoSearchTool: Search using DuckDuckGo Instant Answer API
-
Best for definitions, facts, quick lookups
-
No API key required
-
Returns abstracts, related topics, and infobox data
-
Configuration: API URL
-
BraveSearchTool: Search using Brave Search API
-
Comprehensive web search results
-
Requires API key (paid service)
-
Returns web pages, snippets, and metadata
-
Configuration: API key, URL, result count, safe search settings
-
ExaSearchTool: Search using Exa (formerly Metaphor) API
-
AI-powered semantic search engine
-
Requires API key (paid service)
-
Supports multiple search types: auto, neural, fast, deep
-
Returns rich content with text, highlights, summaries, and metadata
-
Configuration: API key, URL, result count, search type, max characters, max age
== Usage Pattern ==
All search tools follow the Result-based error handling pattern. Use for-comprehensions to chain operations and handle errors gracefully:
Attributes
- Example
-
import org.llm4s.config.Llm4sConfig import org.llm4s.toolapi.builtin.search._ import org.llm4s.toolapi.ToolRegistry import org.llm4s.types.Result // Load and create all search tools using Result val toolsResult: Result[ToolRegistry] = for { // Load DuckDuckGo configuration and create tool duckDuckGoConfig <- Llm4sConfig.loadDuckDuckGoSearchTool() duckDuckGoTool <- DuckDuckGoSearchTool.create(duckDuckGoConfig) // Load Brave Search configuration and create tool braveConfig <- Llm4sConfig.loadBraveSearchTool() braveTool <- BraveSearchTool.create(braveConfig) // Load Exa Search configuration and create tool exaConfig <- Llm4sConfig.loadExaSearchTool() exaTool <- ExaSearchTool.create(exaConfig) // Register all tools tools = new ToolRegistry(Seq(duckDuckGoTool, braveTool, exaTool)) } yield tools // Handle the result toolsResult match { case Right(tools) => // Use tools with agent println(s"Successfully loaded $${tools.tools.size} search tools") case Left(error) => // Handle configuration or validation errors println(s"Failed to load search tools: $${error.message}") }== Individual Tool Usage == You can also load and use tools individually:
import org.llm4s.toolapi.builtin.search.ExaSearchTool // Load just Exa Search val exaToolResult = for { config <- Llm4sConfig.loadExaSearchTool() tool <- ExaSearchTool.create(config) } yield tool exaToolResult match { case Right(tool) => // Use tool case Left(error) => // Handle error }== Configuration == Configure search tools in your application.conf:
llm4s { tools { duckduckgo { apiUrl = "https://api.duckduckgo.com" } brave { apiKey = "your-api-key" apiUrl = "https://api.search.brave.com/res/v1" count = 10 safeSearch = "moderate" } exa { apiKey = "your-exa-api-key" apiUrl = "https://api.exa.ai" numResults = 10 searchType = "auto" # Options: auto, neural, fast, deep maxCharacters = 500 } } }
Members list
Type members
Classlikes
A single image result from the Brave Image Search API.
A single image result from the Brave Image Search API.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
BraveImageResult.type
Image search result container returned by BraveSearchCategory.Image.
Image search result container returned by BraveSearchCategory.Image.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
A single news article result from the Brave News Search API.
A single news article result from the Brave News Search API.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
BraveNewsResult.type
News search result container returned by BraveSearchCategory.News.
News search result container returned by BraveSearchCategory.News.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
Type-class describing a Brave Search category (Web, Image, Video, News).
Type-class describing a Brave Search category (Web, Image, Video, News).
Each case object encodes the API endpoint, the tool name exposed to the LLM, a human-readable description, result parsing logic, and how to map a SafeSearch level to the string the Brave API expects.
Type parameters
- R
-
The Scala type that represents a search result for this category
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
Attributes
- Companion
- trait
- Supertypes
-
trait Sumtrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
BraveSearchCategory.type
Runtime configuration for Brave Search API requests.
Runtime configuration for Brave Search API requests.
Value parameters
- count
-
Number of results to return per request
- extraParams
-
Additional key-value parameters merged into every request
- safeSearch
-
Safe-search filtering level (default: SafeSearch.Strict)
- timeoutMs
-
HTTP request timeout in milliseconds
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
BraveSearchTool.type
A single video result from the Brave Video Search API.
A single video result from the Brave Video Search API.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
BraveVideoResult.type
Video search result container returned by BraveSearchCategory.Video.
Video search result container returned by BraveSearchCategory.Video.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
A single organic web result from the Brave Web Search API.
A single organic web result from the Brave Web Search API.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
BraveWebResult.type
Web search result container returned by BraveSearchCategory.Web.
Web search result container returned by BraveSearchCategory.Web.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
BraveWebSearchResult.type
Content category filter for the Exa Search API.
Content category filter for the Exa Search API.
Restricts search results to pages belonging to a specific vertical. Use with ExaSearchConfig.category to narrow the result set.
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object Companyobject FinancialReportobject Githubobject LinkedinProfileobject Newsobject Pdfobject PersonalSiteobject ResearchPaperobject TweetShow all
Configuration for DuckDuckGo search tool.
Configuration for DuckDuckGo search tool.
Value parameters
- maxResults
-
Maximum number of related topics to return.
- safeSearch
-
Whether to enable safe search.
- timeoutMs
-
Request timeout in milliseconds.
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
DuckDuckGo search result.
DuckDuckGo search result.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
Tool for web searching using DuckDuckGo's Instant Answer API.
Tool for web searching using DuckDuckGo's Instant Answer API.
This tool provides quick answers and definitions without requiring an API key. It's best suited for factual queries, definitions, and quick lookups.
Note: This uses DuckDuckGo's free Instant Answer API which provides:
- Definitions from Wikipedia
- Quick facts
- Related topics
- Disambiguation pages
It does NOT provide full web search results (that would require a paid API).
Architecture: This tool follows the "config at the edge" pattern:
- Configuration is loaded at the application boundary via Llm4sConfig.loadDuckDuckGoSearchTool()
- The loaded DuckDuckGoSearchToolConfig is passed to create() method
- The tool operates with the provided configuration
This keeps the tool implementation pure and testable without direct config dependencies.
Attributes
- Example
-
import org.llm4s.config.Llm4sConfig import org.llm4s.toolapi.builtin.search._ // Load configuration at the application edge val toolConfigResult = Llm4sConfig.loadDuckDuckGoSearchTool() toolConfigResult match { case Right(toolConfig) => // Create the tool with loaded configuration val searchTool = DuckDuckGoSearchTool.create(toolConfig) val tools = new ToolRegistry(Seq(searchTool)) agent.run("What is Scala programming language?", tools) case Left(error) => println(s"Failed to load DuckDuckGo config: $$error") }For testing, you can create a config directly:
import org.llm4s.config.DuckDuckGoSearchToolConfig val testConfig = DuckDuckGoSearchToolConfig(apiUrl = "https://api.duckduckgo.com") val searchTool = DuckDuckGoSearchTool.create(testConfig) - Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
DuckDuckGoSearchTool.type
A single result returned by the Exa Search API.
A single result returned by the Exa Search API.
Value parameters
- author
-
Author name, if available
- favicon
-
URL of the site's favicon
- highlightScores
-
Relevance scores for each highlight
- highlights
-
Relevant text snippets highlighted by Exa
- id
-
Exa's internal document identifier
- image
-
URL of the page's representative image
- publishedDate
-
ISO-8601 date string of the page's publication date
- subPages
-
Nested sub-page results for deep crawl searches
- summary
-
AI-generated summary of the page, if requested
- text
-
Extracted page text (truncated to
maxCharacters) - title
-
Page title
- url
-
Page URL
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Runtime configuration for Exa Search requests. Allows overriding defaults and providing advanced parameters via extraParams.
Runtime configuration for Exa Search requests. Allows overriding defaults and providing advanced parameters via extraParams.
Value parameters
- additionalQueries
-
Additional queries for deep search (optional, default None)
- category
-
Data category (optional, default None)
- extraParams
-
Advanced parameters merged into the request body
- livecrawlTimeout
-
Timeout for livecrawl (optional, default None)
- maxAgeHours
-
Max content age in hours (default 1)
- maxCharacters
-
Max text characters (mandatory, default 500)
- numResults
-
Number of results (mandatory, default 10)
- searchType
-
Search type (mandatory, default Auto)
- timeoutMs
-
Request timeout in milliseconds
- userLocation
-
User location for local search (optional, default None)
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Container for search results returned by the Exa Search API.
Container for search results returned by the Exa Search API.
Value parameters
- query
-
The original search query
- requestId
-
Exa's unique identifier for this request (useful for debugging)
- results
-
Ordered list of matching results
- searchType
-
The search type that was actually applied by Exa
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
ExaSearchResult.type
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
ExaSearchTool.type
A related topic from web search.
A related topic from web search.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
RelatedTopic.type
Safe-search filtering level for Brave Search API requests.
Attributes
- Companion
- trait
- Supertypes
-
trait Sumtrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
SafeSearch.type
Search algorithm type used by the Exa Search API.
Attributes
- Companion
- trait
- Supertypes
-
trait Sumtrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
SearchType.type