03. Core Components
Tool Calling, Function Calling and Action Execution
Tool calling lets an LLM request structured actions. Function calling is the usual API shape. Action execution is your runtime validating, authorizing, running, and returning observations β the difference between a chat reply and an agent.
What you will learn
- Explain tool calling vs function calling vs execution
- Design a clear tool schema the model can use
- Describe the propose β validate β execute β observe loop
- List safety controls for side-effecting actions
- Answer interview questions with short, solid answers
Definition
Tool calling is the pattern where an LLM selects a named capability and arguments instead of (or before) a final user-facing answer. Function calling is the common provider API for that pattern β tools declared with JSON schemas, model returns a structured call object. Action execution is everything after: validate, authorize, run, timeout, log, and feed the result back as an observation.
Without a trusted runtime, βtool callingβ is just fancy text. The agent boundary is where side effects are gated in code.
Introduction
This lesson (#5 in Core Components) follows Memory. Memory stores state; tools change the world and produce new percepts.
Next: API Integration for Agents β how tools wrap real services.
Why tools matter
- Give agents live data and real side effects
- Reduce hallucination by grounding in system results
- Make goals measurable (tests pass, ticket created)
- Enable permissioned automation instead of free-form shell dreams
Tool calling vs function calling vs execution
- Tool calling - product/architecture concept (capabilities the agent may use)
- Function calling - API mechanism (schemas in, structured calls out)
- Action execution - your orchestrator/runtime doing the work safely
- Related - MCP / plugins / connectors are packaging for the same idea
Declaring tools
The model can only choose well if the contract is clear. Vague tools produce vague calls.
- name - stable identifier (create_ticket, run_tests)
- description - when to use / when not to use
- parameters - types, enums, required fields
- returns - document observation shape for the next turn
- errors - predictable error objects the model can recover from
The execution loop
Each agent step may end in a final message or one/many tool calls. Parallel calls are possible when independent; sequential when later args depend on earlier results.
- Build context with available tool schemas
- Model returns assistant message and/or tool_calls
- Runtime allowlists name, validates args, checks authz
- Execute with timeout; capture stdout/result/error
- Append tool observation messages; call model again
- Stop on final answer, goal met, error budget, or human gate
Safe action execution
Treat every model-proposed call as untrusted input to your systems.
- Allowlist - reject unknown tool names
- Schema validate - refuse bad or extra args
- Authz - scope to user/tenant/environment
- Budgets - time, rate, spend, step counts
- HITL - require approval for irreversible or high-cost actions
- Audit - log actor, tool, args (redacted), result, latency
Design tips that improve tool use
- Fewer sharp tools beat one mega βdo_anythingβ tool
- Idempotent writes when retries are likely
- Return concise structured observations, not huge blobs
- Separate read tools from write tools for clearer policy
- Include dry_run or preview for dangerous mutations
Program / implementation notes
Implement a ToolRegistry + ToolRuntime. Keep business APIs behind thin adapters. Never eval free-form code from the model in production.
- Map tool name β handler function in code
- Normalize errors into {ok:false, code, message}
- Correlate tool_call_id across propose and observe
- Eval: golden transcripts of expected tool sequences
- Next: API Integration for Agents
Advantages and limitations
- Advantage: agents can act, not only chat
- Advantage: structured calls are testable and loggable
- Advantage: permissions can be enforced at the boundary
- Limitation: bad schemas β bad arguments
- Limitation: tool storms raise cost and latency
- Limitation: unsafe runtimes turn hallucinations into incidents
Key points
- Tool calling = model requests named actions with arguments.
- Function calling = common structured API for that pattern.
- Action execution = validate, authorize, run, observe in your runtime.
- Clear schemas and allowlists are mandatory.
- High-risk tools need HITL, budgets, and audit logs.
- Observations should be structured and sized for the next prompt.
FAQs
Is function calling the same as fine-tuning?
No. Function calling is an inference-time API where the model emits structured tool requests against declared schemas.
Can the model execute code by itself?
Not safely. It can propose a call; your sandbox/runtime executes. Never trust raw model text as a shell command without a gated tool.
What if the model invents a tool name?
Reject it in the runtime allowlist and optionally tell the model which tools are valid on the next turn.
When should I use parallel tool calls?
When calls are independent (e.g., fetch two docs). Keep them sequential when one result feeds the next arguments.
Interview questions
- What is tool calling in AI agents?
Answer A pattern where the model selects a registered capability and arguments so the system can perform actions or fetch data toward a goal.
- Tool calling vs function calling?
Answer Tool calling is the agent concept; function calling is the typical API form that uses schemas and structured call objects.
- What happens after the model returns a tool call?
Answer The runtime validates and authorizes it, executes the handler, and returns an observation to the model for the next step.
- How do you keep tool use safe?
Answer Allowlists, schema validation, authz, timeouts/budgets, human approval for risky actions, and audit logging.
- What makes a good tool schema?
Answer A clear name, precise description, typed parameters with required fields, and documented success/error observation shapes.
- Why not let the model run arbitrary shell commands?
Answer Because unconstrained execution turns prompt mistakes into security and reliability incidents; expose narrow, reviewed tools instead.
- How do tools relate to ReAct?
Answer ReAct interleaves reasoning with tool actions and observations; tool calling is the structured action channel in that loop.
Related topics
Practice task
Complete each numbered practice step in a notebook or doc before opening the next lesson.
- Write definitions for tool calling, function calling, and action execution.
- Design a schema for run_tests(path, timeout_sec) including required fields.
- List six runtime checks before you would execute a refund tool.
- Sketch propose -> validate -> execute -> observe for one support turn.
- Answer interview questions 1, 3, and 4 in two sentences each.