AgentsDataMap

Helper Functions

View as MarkdownOpen in Claude
from signalwire import create_simple_api_tool

Create a DataMap for a straightforward single-endpoint API call with minimal configuration.

Parameters

name
strRequired

Function name.

url
strRequired

API endpoint URL.

response_template
strRequired

Template string for formatting the response.

parameters
dict[str, dict]

Parameter definitions. Keys are parameter names, values are dicts with "type", "description", and optional "required" keys.

method
strDefaults to GET

HTTP method.

headers
dict[str, str]

HTTP headers.

body
dict[str, Any]

Request body for POST/PUT.

error_keys
list[str]

Keys indicating an error response.

Returns

DataMap — A fully configured DataMap ready for further chaining or conversion.


from signalwire import create_expression_tool

Create a DataMap for pattern-matching responses without API calls.

Parameters

name
strRequired

Function name.

patterns
dict[str, tuple[str, FunctionResult]]Required

Dictionary mapping test values to (pattern, [FunctionResult][ref-functionresult]) tuples.

parameters
dict[str, dict]

Parameter definitions (same format as create_simple_api_tool).

Returns

DataMap — A fully configured DataMap.

Example

from signalwire import AgentBase
from signalwire import create_simple_api_tool, create_expression_tool
from signalwire import FunctionResult
# Simple API tool -- one line instead of a full DataMap chain
weather = create_simple_api_tool(
name="get_weather",
url="https://api.weatherapi.com/v1/current.json?key=KEY&q=${enc:args.city}",
response_template="Weather in ${args.city}: ${response.current.condition.text}",
parameters={
"city": {"type": "string", "description": "City name", "required": True}
},
error_keys=["error"]
)
# Expression tool -- pattern matching without API calls
greeting = create_expression_tool(
name="greet",
patterns={
"${args.language}": (r"spanish|espanol", FunctionResult("Hola!")),
},
parameters={
"language": {"type": "string", "description": "Language to greet in"}
}
)
agent = AgentBase(name="helper-demo")
agent.set_prompt_text("You are a helpful assistant.")
agent.register_swaig_function(weather.to_swaig_function())
agent.register_swaig_function(greeting.to_swaig_function())
if __name__ == "__main__":
agent.run()