Search

Web search via DuckDuckGo, backed by the ddgs package

search runs a real DuckDuckGo query and raises when the backend fails, so missing dependencies and rate limits are visible instead of silent.

Diagram

Search Capability

🔎 search query

🦆 DuckDuckGo

✅ Results

⚠️ RuntimeError

Quick Start

  1. Search from an Agent

    Give an agent the web search tool for research tasks.

    python
    from praisonaiagents import Agent
    from praisonaiagents.tools import internet_search
    
    agent = Agent(
        name="Researcher",
        instructions="Search the web and summarise findings",
        tools=[internet_search]
    )
    
    agent.start("Find the latest news on the PraisonAI framework")
  2. Direct capability call

    Call search directly when you just need raw results.

    python
    from praisonai.capabilities import search
    
    result = search("PraisonAI framework")
    
    for r in result.results:
        print(r["title"], r["url"])

How It Works

Diagram
DuckDuckGo (ddgs)search()UserDuckDuckGo (ddgs)search()Useralt[success][missing ddgs or rate limit]search(“query”)internet_search(query, max_results)resultsSearchResult{“error”: “…”}raise RuntimeError

search calls internet_search under the hood. Each result is a dict with title, url, and snippet keys.


Configuration Options

ParameterTypeDefaultDescription
querystrRequiredSearch query
sourcesList[str]NoneOptional list of sources to search
max_resultsint10Maximum number of results
timeoutfloat600.0Request timeout in seconds
metadataDictNoneOptional metadata for tracing

SearchResult fields: results (list of dicts), query, total, metadata.

Capabilities SDK Reference

Auto-generated reference for the capabilities module


Common Patterns

Handle a missing dependency gracefully:

python
from praisonai.capabilities import search

try:
    result = search("open source LLM agents")
    print(f"{result.total} results")
except RuntimeError as e:
    print(f"Search unavailable: {e}")
    # e.g. install ddgs: pip install ddgs

Async search delegates to the sync path:

python
import asyncio
from praisonai.capabilities import asearch

async def main():
    result = await asearch("vector databases")
    for r in result.results:
        print(r["title"])

asyncio.run(main())

Best Practices

Install ddgs before using search

Run pip install ddgs. Without it, search raises RuntimeError.

Catch RuntimeError

Rate limits and missing dependencies surface as RuntimeError. Wrap calls so your app degrades gracefully instead of crashing.

Tune max_results

Lower max_results for faster, cheaper queries; raise it when you need broader coverage.


Related