Function Call Protocols
Dialects of the same round trip
A function-calling protocol — like the Anthropic tool-use format or OpenAI's — formalizes how models declare calls. Cross-provider abstractions (AI SDK, LangChain) normalize dialects so your app survives model swaps.
What you will learn
- Compare major protocol dialects
- Use a portable abstraction layer
- Map your app across providers cleanly
What is this?
Each provider speaks a slightly different tool-call dialect (message shape, roles, arg serialization). A protocol layer — direct provider calls OR an abstraction like the AI SDK or LangChain — normalizes 'ask model → handle tool_calls → return results' into one shape. That frees your dispatch layer from provider quirks.
Why do you need it?
- Model swaps become config, not rewrites.
- One eval harness covers every provider.
- Abstractions already encode correct multi-turn tool loops.
- Protocol details (role names, JSON.stringify of args) are easy to get wrong by hand.
Mental model
The universal 'insert card' icon
Protocol abstraction
Wireless payment looks identical across banks despite wildly different internals, because a standard icon + protocol (NFC) sits between you and the bank. Your checkout code stops caring which bank — one TAP. That's the value of a tool-call abstraction.
How it works
- Pick a representation: provider-native (OpenAI tools, Anthropic tool_use) or an DSP abstraction (AI SDK tools).
- Declare tools once in your format; let the layer translate.
- Handle the result message containing tool_calls.
- Execute via your dispatcher, feed tool results back through the layer.
- Keep provider-specific edge cases (forced tool_choice, parallel calls) explicit.
Abstraction plane.
In production
- AI SDK or LangChain tool abstractions power standard agent stacks.
- Vendor is config: swap model/provider behind the adapter.
- Protocol-aware middleware logs unified tool-call traces.
Best practices
- Define your tools once at the app layer.
- Validate args in YOUR schemas regardless of provider dialect.
- Pin SDK versions; dialects drift between releases.
- Test the same golden tool-case against every provider.
Common mistakes
- Hand-writing provider glue and re-teaching quirks per vendor.
- Schema translations silently dropping enums or requireds.
- Assuming parallel tool calls are supported identically everywhere.
Common issues
Args serialize as strings or objects inconsistentlyProvider dialect differences
Normalize at the adapter; validate typed args in dispatch.
Abstraction hides a provider-only quirkLeaky abstraction
Escalate to the provider-native API for that edge case.
Debugging tips
- Tool works in provider X not Y → compare translated schema; dialect diff.
- Result message shape varies → normalize into a typed envelope in the adapter.
- Upgrades break loops → pin versions; read changelogs for dialect changes.
Interview checkpoint
Hands-on lab
- Normalize two provider dialects
- Translate your tool list for each
- Adapt results back to a common envelope
Cross-Provider Tool Dialect Shim
35 min · advanced
Quick quiz
A protocol layer's main job is…
Schema fidelity survives translation to every provider automatically.