Push every call to a webhook
Requirement
"After every call, push the transcript to our webhook."
Pieces
- Connection: the webhook's key, provider
http_key. - One tool per action: an HTTP tool that posts to the webhook.
- Post hook: the tool attached as
post_hook_tool_idson the agent draft, then published.
The shape to avoid
Instructions in the prompt telling the model to "send the transcript at the end". The model does not run after the last word, and a tool it could call mid-conversation is one it may forget to call. A post hook runs after the conversation whether or not anybody asked, and its failures land in the interaction's record where they can be found.
Steps
Ids from an earlier step are written as {{step_N.field}}; the test that runs
this page substitutes them.
A hook is called with no arguments from the model. What the webhook receives
is what a human fixed on the instance (fixed_parameters) and nothing else:
the platform's own ids never leave it. To be told which conversation ended, fix
a parameter of your choosing — here conversation_id — to
$ref:conversation.id; it is resolved when the hook runs and arrives in the
payload as the conversation's id. The transcript itself is not in the request;
the webhook reads that id from the payload and fetches the transcript with
get_trace, and the interaction's end reason and duration with
get_interaction.
-
The webhook's key.
create_connectionCode -
The tool.
fixed_parameterstravel with every call; the model never sees them and, in a hook, there is no model to. The webhook receives{"event": "conversation_ended", "conversation_id": "<the id>"}.create_toolCode -
An agent publishes only with an AI profile; one LLM setting makes one.
create_llm_settingsCode -
The profile.
create_profileCode -
The agent.
create_agentCode -
Its draft: the version to edit and the graph to fill.
get_draft(agent_id={{step_5.id}})Code -
A root node.
add_node(graph_id={{step_6.graph_id}})Code -
Named as the root.
set_root(graph_id={{step_6.graph_id}},node_id={{step_7.id}})Code -
The hook is a property of the draft, next to the profile.
edit_draft(version_id={{step_6.id}})Code -
Published: the hook runs after every conversation from here on.
publish_version(version_id={{step_6.id}})Code
What the agent sees
Nothing. The tool is in the post slot, not on a node, so the model is never
offered it; it runs once, after the conversation, and every attempt is a tool
call in the interaction's trace.
Variations
-
Several steps, or a branch: the same work as an automation. Put the webhook tool in a flow and create an automation with
trigger_kind: "interaction_ended"; its run starts withinteraction_id,agent_id,channel,direction,end_reason,started_at,ended_at,duration_seconds,contact_spokeandusage, all readable as$ref:trigger.<key>:Code -
Only calls that ended one way:
trigger_config.end_reasonson that automation lists the end reasons that count. -
Before the conversation instead of after: the same tool in
pre_hook_tool_ids; its output is injected as context for the first word.