Tool Use
Use web search tools with Claude Sonnet 4.6 through a local Nexus gateway.
The source routes requests to Anthropic's retired claude-sonnet-4-20250514 model. Replace it with anthropic/claude-sonnet-4-6 before running. See Anthropic model deprecations.
"""Run `uv pip install ddgs` to install dependencies."""
import asyncio
from agno.agent import Agent
from agno.models.nexus import Nexus
from agno.tools.websearch import WebSearchTools
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
model=Nexus(id="anthropic/claude-sonnet-4-20250514"),
tools=[WebSearchTools()],
markdown=True,
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
# --- Sync ---
agent.print_response("Whats happening in France?")
# --- Sync + Streaming ---
agent.print_response("Whats happening in France?", stream=True)
# --- Async ---
asyncio.run(agent.aprint_response("Whats happening in France?"))
# --- Async + Streaming ---
asyncio.run(agent.aprint_response("Whats happening in France?", stream=True))Run the Example
Configure the gateway in the first terminal
Install Nexus. Create nexus.toml with this loopback-only configuration:
[server]
listen_address = "127.0.0.1:8000"
[llm]
enabled = true
[llm.protocols.openai]
enabled = true
path = "/llm"
[llm.providers.anthropic]
type = "anthropic"
api_key = "{{ env.ANTHROPIC_API_KEY }}"
[llm.providers.anthropic.models."claude-sonnet-4-6"]Start the gateway in the first terminal
Set an Anthropic API key with access to Sonnet 4.6. The gateway process uses this key for upstream model requests.
export ANTHROPIC_API_KEY="your_anthropic_api_key_here"From the directory containing nexus.toml, run nexus. Leave this foreground process running and open a second terminal in your example directory for the remaining steps.
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall the client dependencies in the second terminal
uv pip install -U agno openai ddgsConfigure the current client model
Replace anthropic/claude-sonnet-4-20250514 with anthropic/claude-sonnet-4-6 and add api_key="nexus-local" to Nexus(...) in the saved file. The default URL matches this gateway's http://localhost:8000/llm/v1/ route.
This TOML does not enable client OAuth. The nonempty dummy bearer satisfies the OpenAI SDK; it is not an OpenAI provider key and does not secure the gateway. An OAuth-protected deployment instead needs its required client access token. The Anthropic provider key remains in the gateway terminal.
Run the example in the second terminal
Save the code above as tool_use.py, then run:
python tool_use.pyFull source: cookbook/90_models/nexus/tool_use.py