AI agents with function calling: when they outperform a traditional REST API
Function calling and AI agents don't replace REST APIs — they complement them. Here's when it makes sense to use them, with concrete architectural examples.
Published on November 23, 2026 · 7 min read
The real problem
Six months ago a client came to us with a request: "I want my ERP to answer questions in natural language". The obvious solution was a chatbot wired to a few endpoints. We built an agent with function calling instead. The production difference was clear: the chatbot responded, the agent acted.
That distinction is not semantic. It has a direct impact on architecture, operational costs, and maintenance.
---
What function calling is, without the hype
Function calling is a capability of LLM models (OpenAI, Anthropic, Mistral, Gemini) that lets the model emit a structured call to an external function instead of responding in free text.
In practice: instead of saying "March invoice total is €42,000", the model says "call get_invoices({month: 3, year: 2024})". The runtime executes the function, returns the result, and the model composes the final answer.
Simplified schema:
User → Prompt → LLM
↓ (function call JSON)
Tool executor
↓ (result)
LLM → Final responseA multi-step agent extends this pattern: the model can invoke functions in sequence, evaluate intermediate results, and decide the next step without human intervention.
---
When a traditional REST API is the right answer
Before praising agents, honesty is required: most B2B flows work better with classic APIs.
A REST API is superior when:
- Input is structured and predictable: forms, webhooks, nightly batches.
- Logic is deterministic: compute tax, update order status, generate PDF.
- Latency is critical: under 200 ms, an LLM in the middle is noise.
- Volume is high: 10,000 calls/hour cost cents in tokens if routed through an LLM.
- Audit trail must be exact: every API call is loggable byte by byte.
No AI agent makes sense in these contexts. It would add latency, cost, and failure probability.
---
When function calling beats the REST API
The paradigm shift happens when input is ambiguous, composite, or context-dependent.
Case 1: Multi-system orchestration
A back-office operator writes: "Move order #4421 to next week, notify the supplier, and update the CRM".
With a REST API you have three separate calls, a UI guiding the user step by step, and at least one human coordinating. With an agent:
tools = [
{"name": "update_order_date", "description": "Update order delivery date"},
{"name": "send_supplier_notification", "description": "Send email to supplier"},
{"name": "update_crm_record", "description": "Update record in CRM"}
]
# The LLM decides execution order, handles dependencies,
# and reformulates if a tool returns an errorThe agent runs the three steps in sequence, handles the error if the supplier is unreachable, and reports a summary to the operator. No interface to build, no workflow to design.
Case 2: Unstructured input interpretation
A client uploads a technical specification PDF and asks: "Which of your products meet these requirements?" There is no REST endpoint for this. There is an agent that:
- Extracts requirements from the PDF via
parse_documenttool. - Queries the product catalog via
search_catalogtool. - Filters for compliance via
check_compliancetool. - Composes the response.
Case 3: Decisions requiring reasoning
"Should I renew the contract with this supplier?" — the agent retrieves order history, evaluates SLAs, compares against alternatives in the vendor database, and produces a motivated recommendation. No REST API can encode this reasoning without becoming a rigid, brittle business rule.
---
Concrete risks to manage
Function calling is not free. Production issues we have observed:
1. Tool hallucination: the model invokes a function with invented parameters. Mitigation: strict JSON schema validation, type checking on the executor side, retry with error feedback to the model.
2. Infinite loops: in multi-step agents, the model can cycle on functions returning ambiguous results. Mitigation: maximum iteration limit (max_steps), global timeout.
3. Uncontrolled costs: every step consumes tokens. An agent with 8 tool calls on GPT-4o can cost 10–15× a single response. Mitigation: lighter models for intermediate tool calls (e.g. GPT-4o-mini for routing, GPT-4o only for the final response).
4. Security: an agent with access to delete_record or send_email is an attack surface. Mitigation: least-privilege tool permissions, human approval for irreversible actions (human-in-the-loop), sandbox for testing.
---
Reference architecture for B2B environments
[User input]
↓
[Gateway + auth]
↓
[LLM Orchestrator] ←→ [Tool Registry]
↓ ↓
[Tool Executor] → [Internal REST APIs / DB / External services]
↓
[Response formatter]
↓
[Audit log + monitoring]The Tool Registry is the critical piece: it contains model-readable descriptions, parameter schemas, role-based permissions, and per-tool rate limits. In complex environments it is not a static YAML file — it is a microservice.
---
Operational take-away
Use function calling and AI agents when:
- Input is in natural language and ambiguous.
- Multiple calls to different systems need to be coordinated by contextual logic.
- The cost of building and maintaining a deterministic workflow exceeds the token cost.
Keep REST APIs when:
- Input is structured.
- Latency and per-call cost are hard constraints.
- You need a precise audit trail and deterministic behavior.
The two patterns are not mutually exclusive: AI agents call REST APIs. The question is who coordinates — the code or the model.
---
Evviva Group designs and implements AI agent architectures for IT partners on a white-label basis. If you are evaluating this type of integration, we are available for a technical call.