DuckDuckGoSearchTool

org.llm4s.toolapi.builtin.search.DuckDuckGoSearchTool

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)
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

Create a DuckDuckGo search tool with the given configuration.

Create a DuckDuckGo search tool with the given configuration.

This method follows the "config at the edge" pattern where configuration is loaded at the application boundary and passed in as a parameter.

Value parameters

config

Optional runtime configuration for timeout, maxResults, and safeSearch settings

toolConfig

The tool configuration containing API URL (loaded via Llm4sConfig.loadDuckDuckGoSearchTool())

Attributes

Returns

A configured ToolFunction ready to be registered with the agent

Example
// Load config at application edge
val toolConfig = Llm4sConfig.loadDuckDuckGoSearchTool().getOrElse(
 throw new RuntimeException("Failed to load DuckDuckGo config")
)
// Create tool with custom runtime settings
val searchTool = DuckDuckGoSearchTool.create(
 toolConfig = toolConfig,
 config = DuckDuckGoSearchConfig(
   timeoutMs = 5000,
   maxResults = 5,
   safeSearch = true
 )
)