Function shape
Start with @tool, then async def
Start with @tool, then async def
Every function begins with the
@tool decorator followed by an async def. The function name here must match the Name field on the form.The docstring is the tool description
The docstring is the tool description
This is what the model reads when deciding whether to call the function. Write it for the model: what it does, and when to use it. A vague docstring is the most common reason a function never gets called.
Imports go inside the function
Imports go inside the function
Nothing may sit above
@tool. Put every import in the function body.Return a dict
Return a dict
Always. Return a readable error dict rather than raising — a raised exception reaches the customer as a generic failure with nothing useful in it.
Parameters
Type-annotate every parameter. The model fills them from the conversation, and the Test Run tab reads the same signature to build its input fields. Name parameters after the value they hold —city, order_id — not data or value. The name is part of what the model uses to work out what to put there.
Direct Send
WhatsApp agents only.
message is the text the customer receives, verbatim.
With Direct Send off, the model reads your dict and writes its own reply, so any shape works.
Execution timeout
5 to 120 seconds, default 30, set on the Basic tab. The process is terminated if it exceeds the limit.
Set your own HTTP client timeout below it, as in the example above, so a slow API returns a clean error you control instead of being killed mid-call.
Secrets
x_secrets is a dict of every secret in your account’s Secrets Vault, already decrypted:
Conversation context
x_context is available in every function with no lookup. The phone number keys use the same names as the post-call function variables on voice agents.
The contact record
x_contact is this person’s CRM contact row, already loaded — querying it yourself only costs latency.
update_contact earlier in the same turn, x_contact reflects that change — a function running after it always sees the updated values, never stale ones.
Building and testing
Related
Secrets
Where credentials belong
Functions overview
The other function types