Add a before-call tool
Summary
A before-call tool is a webhook that the platform sends while an inbound call rings, and its response goes into the agent’s system prompt. This guide adds a before-call tool to an agent’s draft and publishes the agent. It does not cover tools that the model calls during the call; see Tools and MCP servers.
Facts
Steps
Set AGENT_ID to the id of the agent that answers your inbound number. listAgents lists the
agents of the workspace, and Route phone calls assigns an agent to a
number. Set SECRET_ID to the id of a secret with purpose webhook_tool that holds the API key
of your lookup service (Secrets and rotation).
1. Read the draft ETag
Set ETAG to the ETag of the answer, including its quotes. It is the draft revision that the
next write needs in If-Match.
2. Add the before-call tool
This tool sends the caller’s number to your lookup service as the phone query parameter, from
the dynamic variable system__caller_id. It sends the API key of the service from the secret in
the X-Api-Key header. It omits deadline_ms and max_response_bytes, so it takes the
before-call defaults: 3000 ms and 4096 bytes.
The 201 answer is the tool. Its configuration has "timing": "pre_call", "deadline_ms": 3000
and "max_response_bytes": 4096. Set ETAG to the ETag of the answer: adding the tool changed
the draft revision.
The response body of your service goes into the system prompt as data, so the agent knows the
caller from its first sentence. Put the placeholder {{lookup_caller}} in the prompt where the data
belongs; without it, the data goes at the end of the prompt. The first message can name one field
of the response with a fallback, for example Hi {{lookup_caller.name|there}}. Edit the prompt and the first message as in
Build and publish an agent.
3. Publish the agent
The tool runs on inbound calls that start after the publish. Calls already admitted keep their
version. The version’s tools list holds the before-call tool with "timing": "pre_call".
Rules
- MUST send
"timing": "pre_call"to make a before-call tool. An omittedtimingon create makes a during-call tool; an omittedtimingon replace keeps the stored timing. - A replace that sends
timingmoves the tool betweenduring_callandpre_call. The tool MUST then meet the rules of its new timing. - MUST NOT send
timingon an MCP tool write: only a webhook tool runs before the call. The API refuses it with400 invalid_request. - MUST NOT give a before-call tool a parameter with
sourcemodel. - MUST send
side_effectnoneandretry_posturenone. The platform sends the request one time and never retries it. - MUST keep
deadline_msfrom 500 to 10000 andmax_response_bytesat most 4096. A value outside 100 to 30000 ms or 256 to 65536 bytes is400 invalid_requestfor every tool, before the before-call bounds apply. - MUST NOT name the tool after an agent variable,
agent_nameorlanguage, or start its name withsystem__. - MUST NOT send a body from a
GETorDELETEtool. Put its values in the query or the path. - MUST send
"timing": "pre_call"tovalidateAgentToolto check a before-call tool. An omittedtimingis checked as a during-call tool. - A slow or failed request does not stop the call: the agent answers without the data.
Verify
Expected output: the tool from step 2, with "timing": "pre_call" in its configuration.
After an inbound call, Read tool call logs shows the run of the tool with
"timing": "pre_call" and no model arguments.