On this page
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.
graph LR
subgraph "Search Capability"
A[๐ search query] --> B[๐ฆ DuckDuckGo]
B --> C[โ
Results]
B --> D[โ ๏ธ RuntimeError]
end
classDef input fill:#8B0000,stroke:#7C90A0,color:#fff
classDef process fill:#189AB4,stroke:#7C90A0,color:#fff
classDef output fill:#10B981,stroke:#7C90A0,color:#fff
classDef warn fill:#F59E0B,stroke:#7C90A0,color:#fff
class A input
class B process
class C output
class D warnQuick Start#
- 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") - Direct capability call
Call
searchdirectly 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#
sequenceDiagram
participant User
participant Search as search()
participant DDG as DuckDuckGo (ddgs)
User->>Search: search("query")
Search->>DDG: internet_search(query, max_results)
alt success
DDG-->>Search: results
Search-->>User: SearchResult
else missing ddgs or rate limit
DDG-->>Search: {"error": "..."}
Search-->>User: raise RuntimeError
endsearch calls internet_search under the hood. Each result is a dict with title, url, and snippet keys.
Configuration Options#
| Parameter | Type | Default | Description |
|---|---|---|---|
query | str | Required | Search query |
sources | List[str] | None | Optional list of sources to search |
max_results | int | 10 | Maximum number of results |
timeout | float | 600.0 | Request timeout in seconds |
metadata | Dict | None | Optional metadata for tracing |
SearchResult fields: results (list of dicts), query, total, metadata.
Auto-generated reference for the capabilities module
Common Patterns#
Handle a missing dependency gracefully:
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 ddgsAsync search delegates to the sync path:
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.