Tool Use
Add web search to a DeepSeek V3 agent on DeepInfra and stream synchronous and asynchronous responses.
Give a DeepSeek V3 agent on DeepInfra web search tools, then stream synchronous and asynchronous responses.
The preserved source selects meta-llama/Llama-2-70b-chat-hf. Use the currently documented DeepSeek V3 model and apply the substitution below before running. See DeepInfra tool calling.
"""Run `uv pip install ddgs` to install dependencies."""
from agno.agent import Agent # noqa
from agno.models.deepinfra import DeepInfra # noqa
from agno.tools.websearch import WebSearchTools # noqa
import asyncio
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
model=DeepInfra(id="meta-llama/Llama-2-70b-chat-hf"),
tools=[WebSearchTools()],
markdown=True,
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
# --- Sync + Streaming ---
agent.print_response("Whats happening in France?", stream=True)
# --- Async + Streaming ---
asyncio.run(agent.aprint_response("What's the latest news about AI?", stream=True))Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno ddgs openaiExport your DeepInfra API key
export DEEPINFRA_API_KEY="your_deepinfra_api_key_here"Use a tool-capable DeepInfra model
Replace meta-llama/Llama-2-70b-chat-hf with deepseek-ai/DeepSeek-V3 in the saved file.
Run the example
Save the code above as tool_use.py, then run:
python tool_use.pyFull source: cookbook/90_models/deepinfra/tool_use.py