DevInterviewMasterStart free →
Agentic AI PatternsFree to read

Tool Use Pattern (Function Calling)

The agent asks for a tool; YOUR code actually runs it

Picture a chef shouting orders to a kitchen: "Two coffees, table four!" The chef doesn't make the coffee — the barista does, then hands it back. Tool Use (also called Function Calling ) works the same way: the LLM doesn't run code or browse the web itself. It outputs a structured request — a tool's name and arguments — and your program executes it and feeds the result back.

Key points

The one-line definition

Tool Use (Function Calling) is a pattern where you describe available tools to the LLM, and instead of answering directly it returns a structured call (tool name + arguments). Your code executes that call and returns the result, which the LLM then uses to continue.

Note: LLM picks the tool and the arguments. Your code does the running.

Who does what (the most important picture)

┌─────────────────┐ ┌──────────────────┐ │ LLM │ │ YOUR CODE │ │ (the brain) │ │ (the runtime) │ └────────┬────────┘ └────────┬─────────┘ │ │ │ 1. "call get_weather(city='Mumbai')" │ │ ───────────────────────────────────────►│ │ (just a REQUEST, not execution) │ │ │ 2. actually │ │ runs the │ │ function │ 3. result: { "tempC": 31 } │ │ ◄───────────────────────────────────────│ │ │ ▼ │

  1. LLM writes the final │

answer using the result │

The full Tool Use round-trip

You give the LLM a goal + a list of tool descriptions │ ▼ ┌────────────────────────────────────────────────────┐ │ LLM decides: "I need the weather tool." │ │ Returns: { tool: "get_weather", │ │ args: { "city": "Mumbai" } } │ └───────────────────────┬────────────────────────────┘ │ your code parses + executes ▼ result = get_weather(city="Mumbai") → 31°C │ hand result back to LLM ▼ ┌────────────────────────────────────────────────────┐ │ LLM: "It's 31°C in Mumbai right now." ✅ │ └────────────────────────────────────────────────────┘

The 4 pieces of Tool Use

A tiny code example (read it like English)

You hand the LLM a list of tool schemas. If it returns a tool call, you look the function up in your own registry, run it, and send the result back. The LLM never executes anything itself.

def get_weather(city):                 # a REAL function you own
    return {"tempC": 31}

TOOLS = {"get_weather": get_weather}   # your tool registry

reply = llm(goal, tools=TOOL_SCHEMAS)  # LLM may ask for a tool

if reply.tool_call:                     # it wants a tool
    name = reply.tool_call.name         # e.g. 'get_weather'
    args = reply.tool_call.args         # e.g. {'city': 'Mumbai'}
    result = TOOLS[name](**args)        # YOUR CODE runs it
    final = llm(goal, tool_result=result)  # LLM uses the result
    print(final.answer)

When should you give the agent tools?

ScenarioRecommendationWhy
The model needs live or private data (DB, API, search)✅ Use Tool UseTools fetch real data the model cannot know on its own.
The task needs exact computation (math, code, dates)✅ Use Tool UseA calculator/code tool is precise; the LLM alone is shaky at arithmetic.
Pure language tasks (rewrite, summarise, translate)❌ No toolsThe model can do these directly; tools add complexity.
You can't validate the tool's inputs/outputs⚠️ Be carefulUnvalidated tool calls (especially write actions) are risky.

Tool Use mistakes (intermediate)

MistakeConsequenceFix
Thinking the LLM runs the tool itself.You never write the executor, so nothing actually happens.Remember: the LLM only REQUESTS; your code parses and runs the function.
Trusting tool arguments blindly.Bad/malicious args reach your DB or shell — a real security hole.Validate and sanitise every argument before executing the tool.
Vague tool descriptions.The LLM calls the wrong tool or passes wrong arguments.Write clear names, descriptions, and typed argument schemas for each tool.
Forgetting to return the result to the LLM.The agent never sees the outcome and can't finish the answer.Always feed the tool result back into the conversation before asking for the final reply.

Remember these 3 lines

Key takeaways

Frequently Asked Questions

What is Tool Use Pattern?

Picture a chef shouting orders to a kitchen: "Two coffees, table four!" The chef doesn't make the coffee — the barista does, then hands it back. Tool Use (also called Function Calling ) works the same way: the LLM doesn't run code or browse the web itself.

How does Tool Use Pattern work?

Tool Use (Function Calling) is a pattern where you describe available tools to the LLM, and instead of answering directly it returns a structured call (tool name + arguments). Your code executes that call and returns the result, which the LLM then uses to continue.

What are the key takeaways about Tool Use Pattern?

Tool Use (Function Calling) has the LLM emit a structured call (tool name + arguments) instead of an answer. Your application code parses and executes the function — the LLM never runs the tool itself. The tool's result is returned to the LLM so it can produce the final answer. Write clear tool schemas and always validate arguments before executing, especially for write actions.

Browse all Agentic AI Patterns topics →

Practice this on DevInterviewMaster

Read the full Tool Use Pattern (Function Calling) breakdown with interactive demos, quizzes, and Hinglish notes.

Open the interactive topic →

800+ system-design, LLD, coding, and design-pattern topics. Unlock everything with Pro (₹499, one-time) or Ultimate (₹999, one-time) — lifetime access, no subscription.