Agents

Helper Functions

View as MarkdownOpen in Claude

The SignalWire SDK exports several helper functions at the top level for common tasks like creating simple contexts, building server-side API tools, and managing the skill registry. All are imported directly from signalwire.

1from signalwire import (
2 create_simple_context,
3 create_simple_api_tool,
4 create_expression_tool,
5 list_skills_with_params,
6 register_skill,
7 add_skill_directory,
8)

create_simple_context

create_simple_context(name="default") -> Context

Create a standalone Context object without needing a full ContextBuilder. Useful for quick single-context agents.

Parameters

name
strDefaults to default

Context name. For single-context agents this must be "default".

Returns

Context — A new Context object ready for adding steps.

Example

1from signalwire import create_simple_context
2
3ctx = create_simple_context()
4ctx.add_step("greet").set_text("Say hello to the caller.")
5ctx.add_step("help").set_text("Ask how you can help today.")

create_simple_api_tool

create_simple_api_tool(name, url, response_template, parameters=None, method="GET", headers=None, body=None, error_keys=None) -> DataMap

Create a server-side API tool with minimal configuration. Returns a configured DataMap that executes an HTTP request on the SignalWire server without requiring a webhook endpoint.

Parameters

name
strRequired

Function name for the SWAIG tool.

url
strRequired

API endpoint URL. Supports ${variable} substitution for injecting parameter values (e.g., "https://api.example.com/search?q=${args.query}").

response_template
strRequired

Template string for formatting the API response. Uses ${response.field} syntax to reference fields from the API response JSON.

parameters
dict[str, dict]

Parameter definitions. Each key is a parameter name, and each value is a dictionary with type, description, and optionally required.

method
strDefaults to GET

HTTP method for the API call.

headers
dict[str, str]

Optional HTTP headers to include in the request.

body
dict[str, Any]

Optional request body for POST/PUT requests.

error_keys
list[str]

JSON keys whose presence in the response indicates an error.

Returns

DataMap — A configured DataMap ready to be added to an agent.

Example

1from signalwire import create_simple_api_tool
2
3weather_tool = create_simple_api_tool(
4 name="get_weather",
5 url="https://api.weather.com/v1/current?key=API_KEY&q=${args.location}",
6 response_template="Weather in ${args.location}: ${response.current.condition.text}, ${response.current.temp_f}F",
7 parameters={
8 "location": {
9 "type": "string",
10 "description": "City name",
11 "required": True
12 }
13 }
14)

For more complex API integrations with multiple webhooks, fallback outputs, or array processing, use the DataMap builder directly.


create_expression_tool

create_expression_tool(name, patterns, parameters=None) -> DataMap

Create a pattern-matching tool that evaluates expressions locally on the SignalWire server without making any HTTP requests. Useful for command routing and conditional responses.

Parameters

name
strRequired

Function name for the SWAIG tool.

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

Dictionary mapping test values to (pattern, [FunctionResult][ref-functionresult]) tuples. The test value is a template string (e.g., "${args.command}"), and the pattern is a regex string matched against it.

parameters
dict[str, dict]

Parameter definitions, same format as create_simple_api_tool.

Returns

DataMap — A configured DataMap with expression-based routing.

Example

1from signalwire import create_expression_tool
2from signalwire import FunctionResult
3
4playback_tool = create_expression_tool(
5 name="playback_control",
6 patterns={
7 "${args.command}": (
8 r"play.*",
9 FunctionResult().add_action("start_playbook", {"file": "${args.filename}"})
10 ),
11 "${args.command}": (
12 r"stop.*",
13 FunctionResult().add_action("stop_playback", True)
14 ),
15 },
16 parameters={
17 "command": {"type": "string", "description": "Playback command", "required": True},
18 "filename": {"type": "string", "description": "File to play"},
19 }
20)

Since dictionary keys must be unique, use separate DataMap.expression() calls via the DataMap builder if you need multiple patterns against the same test value.


list_skills_with_params

list_skills_with_params() -> dict[str, dict[str, Any]]

Return a comprehensive schema for all available skills, including metadata and parameter definitions. Useful for GUI configuration tools, API documentation, or programmatic skill discovery.

Returns

dict[str, dict[str, Any]] — Dictionary keyed by skill name. Each value contains the skill’s metadata and a parameters dictionary describing each configurable parameter with its type, description, required status, hidden flag, and env_var name.

Example

1from signalwire import list_skills_with_params
2
3schema = list_skills_with_params()
4for skill_name, skill_info in schema.items():
5 print(f"{skill_name}: {skill_info.get('description', '')}")
6 for param, meta in skill_info.get("parameters", {}).items():
7 print(f" {param}: {meta['type']} (required={meta.get('required', False)})")

register_skill

register_skill(skill_class) -> None

Register a custom skill class with the global skill registry. This allows third-party code to make skills available without placing them in a specific directory structure.

Parameters

skill_class
typeRequired

A class that inherits from SkillBase. Must define SKILL_NAME and SKILL_DESCRIPTION class attributes.

Example

1from signalwire import register_skill
2from signalwire import AgentBase
3
4class MyWeatherSkill:
5 SKILL_NAME = "my_weather"
6 SKILL_DESCRIPTION = "Custom weather lookup"
7
8 def setup(self):
9 return True
10
11 def register_tools(self):
12 self.define_tool(name="get_weather", handler=self._get_weather, description="Get weather")
13
14 def _get_weather(self, args, raw_data):
15 return {"response": "Sunny, 72F"}
16
17register_skill(MyWeatherSkill)
18
19agent = AgentBase(name="my-agent")
20agent.add_skill("my_weather")

add_skill_directory

add_skill_directory(path) -> None

Add a directory to the skill search path. Skills in this directory should follow the same structure as built-in skills (each skill in its own subdirectory with an __init__.py exporting a SkillBase subclass).

Parameters

path
strRequired

Path to a directory containing skill subdirectories.

Example

1from signalwire import add_skill_directory, AgentBase
2
3add_skill_directory("/opt/custom_skills")
4
5agent = AgentBase()
6agent.add_skill("my_custom_skill") # Found in /opt/custom_skills/my_custom_skill/