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.
Quick 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
search 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.