Curriculum

Agentic AI · External Capabilities

Tool Use & Function Calling

Function calling enables LLMs to invoke external APIs and tools with structured JSON arguments. JSON mode, schema validation, and sandbox execution turn language models into capable action-takers.

The idea

LLMs are trained to recognise when a user request requires an external action (search, compute, DB lookup) and output a structured JSON object instead of prose. The runtime parses the JSON, calls the specified function, and returns the result as a new message in the context.

OpenAI function calling format: provide a list of tool schemas (name, description, parameter JSON schema). The model either outputs a tool_call object or text. The runtime matches the tool name, validates the arguments, executes the tool, and appends the tool result to the conversation.

Sandbox Execution: code generated by LLMs is dangerous to run on host machines. Sandboxes (Docker containers, WebAssembly, Firecracker microVMs, E2B.dev) isolate execution. Security guardrails include output length limits, timeout enforcement, and network access controls.

{"tool": "name", "arguments": {"param": value}}

Standard LLM function call JSON output. The runtime resolves "name" and executes with validated arguments.

What to hold onto

  • Parallel Tool CallsGPT-4o and Claude can call multiple tools simultaneously in one turn, reducing latency on tasks requiring independent lookups.
  • JSON Schema ValidationAlways validate tool arguments against the declared schema before execution. Malformed arguments from hallucinating models must be caught early.
  • Prompt InjectionMalicious content in tool outputs can hijack the agent's next action ("Ignore previous instructions…"). Input sanitisation and instruction hierarchy are defences.

Live: JSON Function Call Schema Validator

Structured tool invocation conforming strictly to JSON Schema definitions with sandboxed execution.

Schema: VALID [RFC 8259]

Quick answers

What is LLM Function Calling?

Function calling enables LLMs to request invocation of external tools by outputting structured JSON describing the tool name and arguments. The runtime executes the function and returns results to the model. This transforms LLMs from text predictors into agents capable of web search, computation, database access, and API orchestration.

Why is sandboxed execution important for AI agents?

LLM-generated code can contain errors, infinite loops, or malicious patterns. Sandboxed execution environments (Docker, WebAssembly, Firecracker) isolate agent code from the host system, enforce resource limits, and allow safe rollback. They are essential for any agentic system that writes and runs code autonomously.