Building AI Agents
Tool Use (Function Calling)
Enabling LLMs to interact with external APIs with strict schema enforcement.
Interview: High - Core agent capability
Advanced Tool Execution
Basic function calling simply returns a JSON string, which breaks heavily in production. Modern AI Engineering requires Strict Schema Enforcement (like Pydantic parsing and OpenAI Structured Outputs) to guarantee valid payloads.
How Function Calling Works
Isolated Sandboxing
Never run LLM-generated code on your backend. Production systems rely on secure micro-VMs (e.g., E2B, Firecracker) to dynamically execute data-analysis code, securely stream the stdout/stderr, and tear down the environment instantly.
Speculative API Execution
Mature agents don't wait sequentially. They employ speculative execution (via asyncio.gather) to execute multiple parallel tools simultaneously, aggressively buying down Time-to-First-Byte (TTFB) latency floors.
Use Cases
Building assistants that can search, calculate, and take actions
Automating workflows that span multiple APIs
Creating coding assistants that can execute and test code
Building agents that interact with databases via natural language
Common Mistakes
Not validating tool arguments before execution — the model can generate invalid inputs
Having tool descriptions that are too vague for the model to use correctly
Not handling tool execution errors gracefully
Giving too many tools (>20) which degrades tool selection accuracy