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

== Usage Pattern ==

All search tools require configuration to be loaded at the application edge:

Attributes

Example
import org.llm4s.config.Llm4sConfig
import org.llm4s.toolapi.builtin.search._
import org.llm4s.toolapi.ToolRegistry
// Load DuckDuckGo configuration
val duckDuckGoConfig = Llm4sConfig.loadDuckDuckGoSearchTool().getOrElse(
 throw new RuntimeException("Failed to load DuckDuckGo config")
)
val duckDuckGoTool = DuckDuckGoSearchTool.create(duckDuckGoConfig)
// Load Brave Search configuration
val braveConfig = Llm4sConfig.loadBraveSearchTool().getOrElse(
 throw new RuntimeException("Failed to load Brave Search config")
)
val braveTool = BraveSearchTool.create(braveConfig)
// Register tools with the agent
val tools = new ToolRegistry(Seq(duckDuckGoTool, braveTool))

== 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"
   }
 }
}

Members list

Type members

Classlikes

case class BraveImageResult(title: String, url: String, thumbnail: String)

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
case class BraveImageSearchResult(query: String, results: List[BraveImageResult])

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
case class BraveNewsResult(title: String, url: String, description: String)

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
case class BraveNewsSearchResult(query: String, results: List[BraveNewsResult])

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
sealed trait BraveSearchCategory[R]

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Image
object News
object Video
object Web

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
case class BraveSearchConfig(timeoutMs: Int, count: Int, safeSearch: SafeSearch, extraParams: Map[String, Value])

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
case class BraveVideoResult(title: String, url: String, description: String)

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
case class BraveVideoSearchResult(query: String, results: List[BraveVideoResult])

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
case class BraveWebResult(title: String, url: String, description: String)

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
case class BraveWebSearchResult(query: String, results: List[BraveWebResult])

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
case class DuckDuckGoSearchConfig(timeoutMs: Int, maxResults: Int, safeSearch: Boolean)

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 Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case class DuckDuckGoSearchResult(query: String, abstract_: String, abstractSource: String, abstractUrl: String, answer: String, answerType: String, relatedTopics: Seq[RelatedTopic])

DuckDuckGo search result.

DuckDuckGo search result.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class 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:

  1. Configuration is loaded at the application boundary via Llm4sConfig.loadDuckDuckGoSearchTool()
  2. The loaded DuckDuckGoSearchToolConfig is passed to create() method
  3. 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 Object
trait Matchable
class Any
Self type
case class RelatedTopic(text: String, url: Option[String])

A related topic from web search.

A related topic from web search.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object RelatedTopic

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
sealed trait SafeSearch

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Moderate
object Off
object Strict
object SafeSearch

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
SafeSearch.type