This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
SignalWire Agents SDK — a Python framework for building AI-powered telephone/messaging agents on SignalWire's platform. Provides SWML (SignalWire Markup Language) document generation, SWAIG (SignalWire AI Gateway) tool calling, real-time call control (RELAY), REST APIs, vector search, and LiveKit compatibility.
Python 3.10+ required. Always activate the venv before running commands:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install -r requirements-dev.txt
# Install in development mode
pip install -e .
# Install with search functionality (various levels)
pip install -e .[search-queryonly] # Query existing .swsearch files only (~400MB)
pip install -e .[search] # Basic search functionality (~500MB)
pip install -e .[search-full] # Full document processing (~600MB)
pip install -e .[search-nlp] # Advanced NLP features (~600MB)
pip install -e .[search-all] # All search features (~700MB)# Run all tests (enforces 95% coverage minimum)
pytest
# Run by marker
pytest -m unit
pytest -m integration
pytest -m core
pytest -m skills
pytest -m cli
# Run tests in specific directories
pytest tests/unit/core/
pytest tests/unit/skills/
# Run single file or test
pytest tests/unit/core/test_agent_base.py
pytest tests/unit/core/test_agent_base.py::TestClassName::test_method
# Parallel execution
pytest -n auto
# Run with verbose output
pytest -v
# Skip coverage enforcement (useful during development)
pytest --no-cov
# Coverage reporting
pytest --cov=signalwire --cov-report=htmlpytest.ini enables --cov-fail-under=95 by default. Test timeout is 300s. Async mode is auto (pytest-asyncio).
# Test SWAIG functions locally
swaig-test examples/simple_agent.py --list-tools
swaig-test examples/simple_agent.py --exec tool_name --param value
# Multi-agent selection
swaig-test examples/multi_agent.py --route /agent-path --list-tools
swaig-test examples/multi_agent.py --agent-class AgentName --exec tool_name
# Control logging output
swaig-test examples/my_agent.py --exec tool_name # Logs suppressed by default
swaig-test examples/my_agent.py --verbose --exec tool_name # Show logs
# Simulate serverless environments
swaig-test examples/my_agent.py --simulate-serverless lambda --dump-swml
# Build search indexes
sw-search ./docs --output knowledge.swsearch
sw-search ./docs ./examples --file-types md,txt,py --output knowledge.swsearch
# Search operations
sw-search validate ./knowledge.swsearch
sw-search search ./knowledge.swsearch "query"
sw-search remote <endpoint> "query" --index-name <name>
# Other tools
sw-pydocs # The SDK's installed docs, for people and coding agents
sw-agent-init # Scaffold new agent projects
sw-agent-dokku # Dokku deployment helper
mcp-gateway # MCP Gateway serviceAgentBase is the central class. It extends SWMLService and composes features via mixins:
SWMLService→ base SWML document generation and FastAPI web servicePromptMixin→ Prompt Object Model (POM) structured prompt buildingToolMixin→ SWAIG function definition/execution (@AgentBase.tool()decorator)SkillMixin→ skill loading/managementWebMixin→ static file serving, route managementAuthMixin→ basic auth, security headersAIConfigMixin→ LLM parameter tuning (temperature, top_p, etc.)ServerlessMixin→ cloud function environment detectionStateMixin→ creates and validates the per-call security tokens for SWAIG functions
AgentServer hosts multiple agents on a single FastAPI process. Agents register at routes. Default port is 3000.
| Module | Purpose |
|---|---|
core/ |
AgentBase, SWML/SWAIG, contexts, data maps, mixins |
skills/ |
17 built-in skill plugins (weather, web_search, datetime, etc.) |
prefabs/ |
Ready-made agent archetypes (InfoGatherer, Survey, FAQ, Receptionist, Concierge) |
relay/ |
WebSocket RELAY client (Blade/JSON-RPC 2.0), async call control |
rest/ |
Synchronous REST client, namespaced API (Fabric, Calling, Video, Datasphere) |
search/ |
Vector search with sentence-transformers, multiple backends |
livewire/ |
LiveKit-compatible API layer mapping to SignalWire |
mcp_gateway/ |
Model Context Protocol bridge to SWAIG |
cli/ |
CLI entry points (swaig-test, sw-search, sw-agent-init) |
SWMLBuilderconstructs SWML JSON documents describing call flowsSWMLServiceserves these documents via FastAPI endpointsSwaigFunctionwraps Python functions as SWAIG tools (defined via@AgentBase.tool())FunctionResultis the return type for all tool functionsSWMLHandlerprocesses incoming AI verb callbacks
ContextBuilder creates multi-step agent workflows. Each Context contains Step objects with prompts, tools, and gather questions. Agents switch contexts at runtime.
- Define contexts with
self.define_contexts()in agent constructor - Single context must be named "default"
- Use
set_valid_steps()andset_valid_contexts()for navigation control - Restrict functions per step with
set_functions(['function_name'])orset_functions("none") - Set completion criteria with
set_step_criteria("condition description")
DataMap defines server-side API tools that execute REST calls without agent webhooks. Supports expression evaluation for conditional logic.
- Created with fluent API:
DataMap('tool_name').description('...').webhook('GET', 'url').output(...) - Variable expansion: a webhook's
urlandparamsread${args.param}and${global_data.key}; itsoutput,expressionsandforeachread the response's fields from the root (${field}) and the arguments as${input.args.param}. Header values aren't expanded. The prefix helperslc:,enc:andfmt_ph:apply in a fixed order (fmt_ph, lc, enc), as in${lc:enc:args.city}; there's noenc:url: - The platform requests one webhook per call, the first whose
require_argsare met; if it fails, the fallback output runs, not the next webhook - Use DataMap for simple API integrations, webhooks for complex logic
Skills are pluggable capabilities loaded via SkillManager and discovered through registry.py. Each skill is a directory under skills/ with a __init__.py exporting a SkillBase subclass.
- Skills are loaded on-demand to avoid startup overhead
- Use
agent.add_skill("skill_name", config_dict)for configuration - Skills automatically register with agent's SWAIG function registry
- Multiple instances of same skill supported with different
tool_name
- Always inherit from
AgentBasefor standard agents - Use
AgentServerfor multi-agent deployments - Implement SWAIG functions with proper error handling
- State management is optional but recommended for complex workflows
- Synchronous tool handlers and callbacks run in worker threads, so handlers for different calls run concurrently: guard shared state; a tool method's
selfis the shared agent, or the request's copy when a per-request configuration callback is set (SWML_SYNC_HANDLERS_INLINE=truerestores one-at-a-time)
- Use
set_prompt_llm_params(**params)to customize main prompt behavior - Use
set_post_prompt_llm_params(**params)for different post-prompt parameters - Common parameters: temperature, top_p, presence_penalty, frequency_penalty. Interruption isn't an LLM parameter: tune it with AI params such as
set_param("barge_min_words", 2)orenable_barge - No defaults are sent unless explicitly set
- Basic auth credentials auto-generated unless environment variables set
- Session management via
SessionManagerfor stateful interactions - Function-specific security tokens supported
- SSL/HTTPS support with
SWML_SSL_ENABLEDenvironment variable
- Local development: Direct agent instantiation with
agent.serve() - Multi-agent servers: Use
AgentServerclass - Serverless: Lambda, CGI, Cloud Functions, Azure Functions supported
- Dynamic configuration: Per-request agent customization for multi-tenancy
- Create directory in
signalwire/skills/skill_name/ - Implement skill class inheriting from
SkillBasewith required attributes:SKILL_NAME(required)SKILL_DESCRIPTION(required)SKILL_VERSION(optional, defaults to "1.0.0")REQUIRED_PACKAGES(list of required Python packages)REQUIRED_ENV_VARS(list of required environment variables)
- Implement required methods:
setup()method returning bool for success/failureregister_tools()method that callsself.define_tool()
- Include README.md with usage documentation
- Add unit tests in
tests/unit/skills/
- Use
swaig-testfor local function testing - Test SWML generation with
--dump-swml - Simulate serverless environments with
--simulate-serverless - Use pytest for comprehensive test coverage
- Install search extras:
pip install -e .[search-full] - Use
sw-searchCLI tool:sw-search ./docs --output knowledge.swsearch - Test with
SearchEngineclass orsw-search search ./knowledge.swsearch "query" - Deploy with
search-queryonlyfor production efficiency
Version is tracked in three places (keep in sync): pyproject.toml, signalwire/signalwire/__init__.py, and signalwire/signalwire/agent_server.py (the FastAPI app version= kwarg in AgentServer.__init__).
Key variables for local development:
SIGNALWIRE_PROJECT_ID,SIGNALWIRE_API_TOKEN,SIGNALWIRE_SPACE— auth for RELAY/REST clientsSWML_BASIC_AUTH_USER,SWML_BASIC_AUTH_PASSWORD— agent server auth (auto-generated if unset)SWML_PROXY_URL_BASE— external URL when behind a reverse proxySWML_SSL_ENABLED,SWML_SSL_CERT_PATH,SWML_SSL_KEY_PATH— HTTPS config