<aside> ๐ŸŽ™๏ธ

Date: Friday, October 9, 2026 ยท Week 2, Day 12 ยท Type: Build Day + Live Session 4 (7:30 PM IST, 90 min)

</aside>

Learning Manual

12.1 Extending LLMs with Tools โ€” how an LLM decides when to call an external function (e.g., calculator, weather API, database lookup).

12.2 Function Schemas โ€” describing Python functions to an LLM using JSON schemas (name, description, parameter types).

12.3 The Execution Loop โ€” model returns function name & arguments โ†’ local app runs function โ†’ result fed back to model โ†’ final answer generated.

The Daily Build

Build an "AI Math Assistant" that gives an LLM access to two local Python tools (calculate(expression) and get_stock_price(ticker)), parses the model's tool-call request, executes the Python function, and returns the verified answer.

Architecture Diagram

+-------------+     +--------------------+     +------------------------+
| User Query  | --> | LLM Decision Engine| --> | Tool Call Request JSON |
+-------------+     +--------------------+     +------------------------+
                                                           |
                                                           v
[Final Answer] <--- [Feed Result Back to LLM] <--- [Execute Python Tool]

Interview Questions

  1. How does native model function calling (e.g., OpenAI Tool Calling) differ from asking an LLM to write code in plain text?
  2. How do you prevent an LLM from calling dangerous tools or passing malicious parameters to a local function?
  3. What happens if a tool function throws an exception during execution? How should the system report this back to the model?

Problem Statement

Problem 12. Build a Python tool dispatcher class ToolRegistry where functions can be registered using a @register_tool decorator, and an execute(tool_name, **kwargs) method dynamically validates arguments and executes the corresponding function.

AI-DSA Primitive

Data Structure: Function Lookup Registry (Dispatch Table).

Mechanics: Hash map storing function names mapped directly to executable Python callable references.

Real-World Production Use: Core mechanism inside OpenAI Assistant SDK, LangChain Agents, and Semantic Kernel.

Software Design Pattern