Tool Use

Give a local LlamaCpp model web search tools and stream the tool-assisted answer.

tool_use.py
"""Run `uv pip install ddgs` to install dependencies."""

from agno.agent import Agent
from agno.models.llama_cpp import LlamaCpp
from agno.tools.websearch import WebSearchTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

agent = Agent(
    model=LlamaCpp(id="ggml-org/gpt-oss-20b-GGUF"),
    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)

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno ddgs openai

Install llama.cpp

Install the llama-server binary. This command supports macOS and Linux with Homebrew; see the llama.cpp installation guide for other platforms:

brew install llama.cpp

Start llama.cpp

Serve ggml-org/gpt-oss-20b-GGUF at http://127.0.0.1:8080/v1:

llama-server -hf ggml-org/gpt-oss-20b-GGUF --ctx-size 0 --jinja -ub 2048 -b 2048

Run the example

Save the code above as tool_use.py, then run:

python tool_use.py

Full source: cookbook/90_models/llama_cpp/tool_use.py