Lesson 02.10 · Phase 02 · Tool Use & Function Calling

Native function calling across providers

Every provider does tool calling the same way in principle and differently on the wire. Keep one neutral tool layer, and write a small adapter per provider for the three places they differ.

Learning objectives

  • Name the three places tool calling differs between providers: declaring tools, reading calls, and sending results.
  • Implement adapters for OpenAI Chat Completions, Anthropic Messages, Google Gemini and Ollama's native API around neutral ToolSpec, ToolCall and ToolResult types.
  • Handle the traps: arguments as a JSON string versus an object, missing call ids, results that must be grouped in one message, and schema keywords a provider rejects.
  • Run the same round trip through two wire formats and get the same answer.

Your agent works on one provider. Then you need another: for cost, a fallback (Phase 3 · Lesson 6), a local model, or a customer's requirement. The model's behaviour is roughly the same, but the JSON isn't:

Loading the full lesson…