Manage AI agents
AI agents follow up with leads for the business: SMS agents text them and email agents email them. Use these endpoints to list agents, read and edit their instructions, and choose which one handles a new lead. The Agents reference has the full schemas.
| Task | Endpoint | Scope |
|---|---|---|
| List SMS agents | GET /v2/pub/agents/sms |
agents:read |
Read one agent, including its instructions and version |
GET /v2/pub/agents/sms/{agentId} |
agents:read |
| Create an agent (a copy of the default agent) | POST /v2/pub/agents/sms |
agents:write |
| Edit an agent | PATCH /v2/pub/agents/sms/{agentId} |
agents:write |
| Choose the agent that texts a new lead | smsAgentId on POST /v2/pub/leads/sms |
— |
| List email agents | GET /v2/pub/agents/email |
agents:read |
| Read one email agent | GET /v2/pub/agents/email/{agentId} |
agents:read |
| Edit an email agent | PATCH /v2/pub/agents/email/{agentId} |
agents:write |
| Choose the agent that emails a new lead | emailAgentId on POST /v2/pub/leads/email |
— |
API keys with no scopes set, or with ALL_SCOPES, have both agent scopes. A restricted key needs them granted in Settings → API Keys.
How SMS agents work
- Every account has exactly one default SMS agent. It texts SMS leads for new contacts that do not name an agent; for an existing contact, leaving out
smsAgentIdkeeps the agent they already have. Which agent is the default cannot be changed. An account can have 5 SMS agents in total, including the default. - Each agent has instructions: what it should ask and say when it texts leads.
instructionModesays what the agent follows:FREEFORMagents followinstructions;DATA_FIELDSagents follow a list of questions (data fields) set up in LeadTruffle and ignoreinstructions. isActivesays whether the agent can be chosen for new leads.qualifierEnabledsays whether its AI replies to texts at all.- When a lead is created with
smsAgentId, that agent is saved on the contact and handles later texts with them too. - SMS agents cannot be deleted through the API; turn one off with
isActive: false. - Edits take effect immediately, including in conversations that are already underway.
Edit an agent safely
- Read the agent:
GET /v2/pub/agents/sms/{agentId}. Note itsversionand its currentinstructions. - Send only the fields you want to change, with that version as
expectedVersion.instructionsreplaces the whole text: to add or change one line, edit the full instructions you read and send the complete result.
curl --request PATCH \
--url 'https://pub-api.leadtruffle.com/api/v2/pub/agents/sms/AGENT_ID' \
--header 'X-API-Key: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"expectedVersion": "VERSION_FROM_YOUR_READ",
"instructions": "Ask for the address and the roof problem, then offer a free inspection.",
"maximumMessagesLimit": 15
}'
- The response has the updated agent and its new
version.
If someone changed the agent after you read it, in the dashboard or through the API, the edit is rejected with 409 VERSION_CONFLICT and nothing changes. Read the agent again, apply your edit to the current settings, and send the new version. This keeps an edit from silently overwriting someone else's.
Every edit is recorded in the account's AI behavior history (the change log in LeadTruffle's AI settings), under your API key's label, so the business can see what changed and undo it in LeadTruffle. data.historyChangeId identifies the record, or is null when the edit changed nothing.
If an AI assistant makes the edit: show the person the exact change and get their OK before sending it, because edits reach live conversations at once.
Email agents
Email agents reply to leads by email from addresses on the business's own email domain. They need that domain set up with LeadTruffle and its DNS records verified (Settings → Email); the shared LeadTruffle email domain cannot be used, and requests return 403 CUSTOM_EMAIL_DOMAIN_REQUIRED without it. Email agents are created in LeadTruffle (Email Gateway); through the API you can list, read and edit them.
- You can edit an email agent's
label(up to 60 characters),enabled,instructions(up to 5,000 characters) andsenderDisplayName, with the same version check and history as SMS agents. As with SMS agents,instructionsreplaces the whole text. isDefaultmarks the agent used for email leads that do not name one. The default is set in LeadTruffle (Settings → Email), not through the API.- Email agents cannot be created or deleted through the API. A turned-off agent's address rejects all email, including replies in live conversations, so
enabled: falseis refused (AGENT_IN_USE) for the default agent or one that received email in the last 30 days. Turn those off in LeadTruffle. - Undoing an email agent edit in LeadTruffle's AI behavior history restores only these fields, never its SMS follow-up or other settings.
- Agents with
canCreateLeads: false(turned off, or Google LSA and Angi agents that only reply to those emails) cannot start conversations with new leads.
Rules and errors
Agent endpoints use a different error shape from the lead endpoints: { "success": false, "error": { "code", "message" } }, so read error.code here (lead endpoints put code at the top level). Branch on the code; the message says what happened and what to do next. A rejected edit changes nothing.
| HTTP | code |
Meaning | What to do |
|---|---|---|---|
| 400 | INVALID_REQUEST |
A field is invalid, or not one you can set here. The message lists each one. | Fix the fields and retry. |
| 400 | DEFAULT_AGENT_LOCKED |
SMS only. The default agent's name, description and active state cannot change. | Edit only its instructions and settings. |
| 400 | INSTRUCTIONS_NOT_USED |
SMS only. The agent follows data fields, so instructions would be ignored. | Send instructionMode FREEFORM with the instructions to switch it. |
| 401 | UNAUTHORIZED |
Missing or invalid API key. | Check the X-API-Key header. |
| 403 | FORBIDDEN |
The key lacks agents:read or agents:write. |
Grant the scope in Settings → API Keys. |
| 403 | CUSTOM_EMAIL_DOMAIN_REQUIRED |
Email only. Email agents need a verified custom email domain. | Ask the business to set it up in LeadTruffle. |
| 404 | AGENT_NOT_FOUND |
No agent with this ID on this account. | List agents to find the right ID. |
| 409 | VERSION_CONFLICT |
The agent changed after you read it. | Read it again and re-apply your edit. |
| 409 | AGENT_NAME_TAKEN |
SMS only. Another agent has this name. | Choose a different name. |
| 409 | AGENT_LIMIT_REACHED |
SMS only. The account already has 5 SMS agents. | Edit an existing agent instead. |
| 409 | AGENT_IN_USE |
SMS: a lead source (Meta, Yelp, Thumbtack, Angi, a Custom Lead Source, or an email gateway's SMS follow-up) still sends leads to this agent, so it and its AI can't be turned off here. Email: the agent is the default, or received email in the last 30 days. | Make the change in LeadTruffle. |
| 409 | AGENT_SETTINGS_UNREADABLE |
The agent's saved settings could not be read, so nothing was changed. | Contact support. |
| 429 | RATE_LIMIT_EXCEEDED |
600 API requests in 10 minutes, shared with the lead, analytics and /v1 endpoints. |
Wait retryAfterSeconds (included here). |
| 503 | SERVICE_UNAVAILABLE |
A temporary problem. A read changed nothing, but a create or edit may or may not have been saved. | Retry a read. Before retrying a create or edit, list or get the agent to see whether it was saved. |
Booking settings are read-only here. Change how an agent books appointments in LeadTruffle.