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

1from signalwire import AgentBase, DataMap
2
3status_check = (
4 DataMap("check_status")
5 .purpose("Check service status")
6 .parameter("service", "string", "Service name", required=True)
7 .webhook("GET", "https://api.example.com/status/${enc:args.service}")
8 .webhook_expressions([
9 {
10 "string": "${response.status}",
11 "pattern": "healthy",
12 "output": {"response": "Service ${args.service} is running normally."}
13 },
14 {
15 "string": "${response.status}",
16 "pattern": "degraded|down",
17 "output": {"response": "Service ${args.service} is experiencing issues."}
18 }
19 ])
20)
21
22agent = AgentBase(name="status-agent")
23agent.set_prompt_text("You are a helpful assistant.")
24agent.register_swaig_function(status_check.to_swaig_function())
25
26if __name__ == "__main__":
27 agent.run()