Course overview

Tool Calling and Function Execution Patterns

From text generation to action

Here's the thing, an LLM on its own is just a text generator. You ask it to book a meeting or pull sales data, and all it can do is tell you how someone might do that. Tool calling is what transforms that passive oracle into an active agent. It's the I/O layer that lets a model invoke external APIs, databases, and systems with structured function calls.

Think of it like this: instead of generating the sentence "You could call the Salesforce API with these parameters," the model emits a structured tool call, function name, typed parameters, and your orchestration layer actually executes it. The model gets back real results ("Account created, ID: 001XYZ") and can reason about them in the next turn. From what I've seen, this is where agents go from interesting demos to production workflows.

The ReAct pattern (Reasoning + Acting, formalized by Shunyu Yao in 2022) made this loop canonical: Thought → Action → Observation → repeat. The agent thinks about the current state, calls a tool, observes the result, and thinks again. It's adaptive, exploratory, and surprisingly effective, Yao's CTF cybersecurity agent hit 83% task completion with GPT-4o using pure ReAct.

Flow diagram showing ReAct cycle: Thought leads to Action, Action produces Observation, Observation feeds back to next Thought
The ReAct loop in action: agents think about the current state, take an action using tools, observe the result, and reason again, continuing until the goal is reached.

Check your understanding

A sales lead qualification agent needs to search your CRM for recent conversations, analyze fit, and segment the lead. Which pattern best describes how it would accomplish this with tool calling?

The engineering reality behind tool execution

Let me be honest, the bottleneck isn't the LLM deciding which tool to call. GPT-4o, Claude 3.5, and Gemini 1.5 are all excellent at tool selection when you give them clear schemas. The hard part is the infrastructure around it: authentication, error handling, API integration, schema validation, and secure execution. I've seen teams spend weeks on prompt tuning when the real problem was retry logic for flaky APIs.

Modern tool calling in 2026 looks like this: dynamic tool discovery (often via Model Context Protocol or vector stores), LLM processing to understand intent, tool selection with structured outputs, actual execution in a sandboxed runtime, result processing, and response formation. Composio's 2026 guide breaks this into six distinct stages, it's a full pipeline, not a single model call.

Here's a concrete example from Salesforce workflows: your agent calls the Salesforce API to create an Account record, parses the response to extract the new AccountID, then uses that ID in a second tool call to create a Task and assign ownership. That's state management across tool calls, you need to thread context, handle partial failures, and decide whether to retry or escalate. That's engineering, not just prompting.

The autonomy-reliability tradeoff

Agent autonomy introduces unpredictability and new failure modes. Production systems need guardrails, iteration caps, human-in-the-loop checkpoints, confidence thresholds, to balance autonomy with reliability. More autonomy is not always better; it's about choosing the right level for your risk tolerance and workflow.

Check your understanding

Planning strategies: when to think ahead vs. react in the moment

ReAct is adaptive and exploratory, but it has a problem: it can be expensive and myopic. If you're running a well-defined multi-step workflow, say, processing a customer inquiry by validating contact info, checking account status, routing to a team, and logging the interaction, you don't want the agent reasoning from scratch at every step. That's where Plan-and-Execute comes in.

The pattern is simple: a Planner agent decomposes the goal into ordered steps without calling any tools, and an Executor (typically a ReAct agent) runs those steps in sequence. IBM's multi-agent RAG system and Oracle's enterprise inquiry workflows both use this separation. It's efficient for structured tasks, but rigid, the plan is fixed upfront, so you lose adaptability if something unexpected happens mid-execution.

Here's what I've seen work in production: hybrid planning (sometimes called ReAct&Plan). Generate a rough plan upfront to avoid local optimization traps, then execute step-by-step with freedom to deviate based on real-time feedback. The CTF cybersecurity agent jumped from 83% success (pure ReAct) to 95% when augmented with an initial planning step. You get the foresight of planning and the adaptability of reactive loops. Chi Wang and Qingyun Wu from AG2 (formerly AutoGen) have been pushing this as the default for production agents since early 2025.

Key ideas: it can be expensive and myopic. Planner agent decomposes the goal into ordered steps. hybrid planning
Key ideas from this lesson, grouped for review.

Planning is not a one-time event

Modern production agents use hybrid planning, generating an initial plan but continuously reasoning and re-planning based on execution results. This combines the foresight of upfront strategy with the adaptability of reactive loops, preventing both myopic local optimization and brittle over-commitment to a fixed plan.

Check your understanding

You're building an agent to process enterprise customer inquiries: validate contact info, check account status, route to the appropriate team, and log the interaction. Would you choose pure ReAct, Plan-and-Execute, or hybrid planning? Explain your reasoning and what tradeoffs you're prioritizing.

Key takeaways

  • Tool calling transforms LLMs from passive text generators into active agents by enabling structured function calls to external APIs, databases, and systems.
  • The ReAct pattern (Thought → Action → Observation → repeat) is foundational, but the engineering bottleneck is infrastructure, auth, error handling, state management, not LLM reasoning.
  • Plan-and-Execute is efficient for structured workflows; pure ReAct is adaptive but expensive; hybrid planning (plan upfront, adapt during execution) is the production default in 2026.
  • Production agents need guardrails, iteration caps, human-in-the-loop checkpoints, confidence thresholds, to balance autonomy with reliability.

Your product check-in

Apply “Tool Calling and Function Execution Patterns” to a product or workflow you know. What would you try, what could go wrong, and what evidence would help you decide?

Ask AI
AI Learning Assistant