AgentsDataMap

webhook_expressions

View as MarkdownOpen in Claude

Add expressions that run after the most recently added webhook completes. Allows conditional output based on the API response.

Parameters

expressions
list[dict[str, Any]]Required

List of expression definitions to evaluate against the webhook response.

Returns

DataMap — Self for method chaining. Raises ValueError if no webhook has been added yet.

Example

from signalwire import AgentBase, DataMap
status_check = (
DataMap("check_status")
.purpose("Check service status")
.parameter("service", "string", "Service name", required=True)
.webhook("GET", "https://api.example.com/status/${enc:args.service}")
.webhook_expressions([
{
"string": "${response.status}",
"pattern": "healthy",
"output": {"response": "Service ${args.service} is running normally."}
},
{
"string": "${response.status}",
"pattern": "degraded|down",
"output": {"response": "Service ${args.service} is experiencing issues."}
}
])
)
agent = AgentBase(name="status-agent")
agent.set_prompt_text("You are a helpful assistant.")
agent.register_swaig_function(status_check.to_swaig_function())
if __name__ == "__main__":
agent.run()