# How to Integrate AI Agents with Legacy CRM and ERP Systems

> How conversational AI agents connect to legacy CRM and ERP systems through APIs in real time, and what the integration needs to work in production.

- **HTML version:** https://dev.tolky.to/en/blog/conversational-ai-legacy-systems-integration-crm-erp
- **Author:** [Marlos Carmo](https://dev.tolky.to/en/author/marlos), Co-founder of Tolky
- **Published:** June 6, 2026
- **Reviewed:** November 15, 2026
- **Language:** en

## Summary

With Function Calling, the AI agent turns the customer's natural language into validated calls to CRM and ERP APIs and translates the technical response back into dialogue. This guide details a tool contract: schema, authorization, timeout, idempotency and fallback.

When the impact of AI on the enterprise market is discussed, the focus usually lands on language fluency. For CTOs and software architects, the real conversation is different: an AI that only "talks" well is of little use at scale. If a customer wants to cancel a plan, the AI has to query the billing system, check contract rules in the ERP and record the cancellation.

This guide shows, behind the scenes, how **conversational AI** integrates with **legacy systems** (CRM, ERP, databases). For the business view, read [AI without integration becomes an FAQ](https://dev.tolky.to/en/blog/ai-without-integration-becomes-faq); for the CRM-specific case, see [AI integration with CRM](https://dev.tolky.to/en/blog/ai-crm-integration-salesforce-hubspot) and the [AI CRM guide](https://dev.tolky.to/en/blog/what-is-ai-crm-complete-guide-2026).

---

## How AI learns to act: Function Calling

Historically, connecting a chat to a database required rigid paths: the "My Orders" button fired a fixed `GET` to `/api/orders/{userId}`. With state-of-the-art LLMs, the architecture uses **Function Calling (tool calling)**. Besides the conversation history, the agent receives the system's **API schema** and chooses which tool to call.

**The technical sequence:**

1. **Intake:** the customer writes on WhatsApp: _"This month's motorbike installment hasn't cleared yet, can you check?"_
2. **Reasoning:** the LLM understands the intent: fetch the financial status of the tax ID tied to the phone number for the current month.
3. **Tool selection:** among the connected tools, it picks `buscar_status_fatura_erp`.
4. **Payload:** it generates validated JSON (e.g. `{"cpf": "12345678900", "mes_referencia": "06-2026"}`) and returns it to the orchestration layer.
5. **Execution:** orchestration fires the HTTPS request to the ERP and receives the raw response (e.g. `"status": "pending_clearing_bank"`).
6. **Natural reply:** the agent translates: _"I checked: your payment is processing, waiting for bank clearing. Since the bank slip was paid yesterday, it can take up to 48 business hours."_

### A tool contract: `buscar_status_fatura_erp`

| Item | Definition |
| :--- | :--- |
| **Input** | Validated schema: valid tax ID and reference month; any other field is rejected |
| **Per-operation authorization** | Read allowed; write (e.g. duplicate invoice, refund) requires its own permission |
| **Timeout** | For example, 8 seconds, with a wait message to the customer while the query runs |
| **Reprocessing** | Idempotent: an idempotency key prevents the same write from running twice |
| **Confirmation** | After a write, read the record back to confirm the data was stored |
| **Failure or ERP down** | The agent reports the instability, logs a ticket number and escalates to a human with a summary, without inventing an answer |

---

## Legacy system challenges

In practice, not every API is modern, clean and fast. Banks, manufacturers and health insurers run on systems 10 or 20 years old. Two obstacles show up often.

### SOAP and XML

While the agent works with JSON, many enterprise systems still expose SOAP and XML. The architectural pattern is a _middleware_ layer: the agent always generates and reads JSON; the middleware converts to XML, authenticates against the legacy server and translates the response back. At Tolky, integrations are done through API and MCP agent, depending on the project; ask the team about your system.

### Latency

An ERP that takes 12 seconds to answer leaves the customer hanging. The recommended pattern is asynchronous conversation: while the query runs, the agent sends a wait message ("one moment, I'm checking your order") and, if the timeout is exceeded, escalates to a human.

---

## Security, governance and guardrails

The classic CTO question is: _"what if the AI starts refunding every customer?"_. In a well-designed enterprise architecture, the LLM **never accesses the database directly**: it only requests actions from a layer that validates each one.

- **Restricted authentication:** the agent has no admin password. Orchestration applies a token scoped to that customer and session; if the model asks for another customer's data, the API rejects it with a 403 error.
- **Limits in code:** a limit such as `if (discount > 30) throw Error` lives in the integration layer and cannot be influenced by prompts.
- **Human approval:** for high-risk actions (cancelling an insurance policy, for example), the agent builds the request and a supervisor approves before execution.

These are architecture patterns. The controls available in each Tolky plan and project (access profiles, audit trail, SSO on Enterprise) are described in [plans](https://dev.tolky.to/en/pricing); the rest should be validated per project.

---

## The intelligence loop: writing back to the CRM

A good integration is not one-way. After a 40-minute service interaction resolving a return, the agent can generate a three-line summary (_"customer unhappy with logistics delay, kept the subscription after a 15% discount"_) and update the customer card in the CRM (Salesforce, HubSpot or Tolky's own CRM) via API. Whoever reads the record later does not need to scroll through hundreds of messages.

---

## Technical verdict

The difficulty of scaling AI in enterprise environments is not model choice, but **reliable integration and API orchestration** across fragmented architectures. A good LLM does not make up for fragile data pipes or the lack of limits at the API level.

The shift of 2026 is that software no longer just talks: it executes, with rules, permissions and an audit trail.

**Want to validate with your ERP or CRM?** Bring one system and validate, in a pilot, one read case and one write case. [Talk to our team](https://dev.tolky.to/en/contact), see the [plans](https://dev.tolky.to/en/pricing) or explore the [solutions](https://dev.tolky.to/en/solutions).

---

This is the Markdown version of the page. The full version, with images and navigation, is at https://dev.tolky.to/en/blog/conversational-ai-legacy-systems-integration-crm-erp

Tolky: https://dev.tolky.to
