Skip to content

About

SignalWire AI Agents Go SDK, Relay and REST

Resources

Code of conduct

Contributing

Security policy

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

361 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SignalWire SDK for Go

Build AI voice agents, control live calls over WebSocket, and manage every SignalWire resource over REST -- all from one package.

Documentation · Report an Issue · pkg.go.dev

Discord MIT License GitHub Stars


What's in this SDK

Capability What it does Quick link
AI Agents Build voice agents that handle calls autonomously -- the platform runs the AI pipeline, your code defines the persona, tools, and call flow Agent Guide
RELAY Client Control live calls and SMS/MMS in real time over WebSocket -- answer, play, record, collect DTMF, conference, transfer, and more RELAY docs
REST Client Manage SignalWire resources over HTTP -- phone numbers, SIP endpoints, Fabric AI agents, video rooms, messaging, and 18+ API namespaces REST docs
go get github.com/signalwire/signalwire-go/v3

AI Agents

Each agent is a self-contained microservice that generates SWML (SignalWire Markup Language) and handles SWAIG (SignalWire AI Gateway) tool calls. The SignalWire platform runs the entire AI pipeline (STT, LLM, TTS) -- your agent just defines the behavior.

package main

import (
	"fmt"
	"time"

	"github.com/signalwire/signalwire-go/v3/pkg/agent"
	"github.com/signalwire/signalwire-go/v3/pkg/swaig"
)

func main() {
	a := agent.NewAgentBase(
		agent.WithName("my-agent"),
		agent.WithRoute("/agent"),
	)

	a.AddLanguage(map[string]any{
		"name": "English", "code": "en-US", "voice": "rime.spore",
	})
	a.SetPromptText("You are a helpful assistant.")

	a.DefineTool(agent.ToolDefinition{
		Name:        "get_time",
		Description: "Get the current time",
		Handler: func(args map[string]any, rawData map[string]any) *swaig.FunctionResult {
			now := time.Now().Format("03:04 PM MST")
			return swaig.NewFunctionResult(fmt.Sprintf("The time is %s", now))
		},
	})

	a.Run()
}

Test an agent with the swaig-test CLI. Unlike the Python tool (which loads an agent source file), the Go tool drives a running agent over HTTP via --url, so start the agent first, then point swaig-test at its URL:

# Terminal 1: run the agent (this one serves on :3001/simple)
go run ./examples/simple_agent/main.go

# Terminal 2: introspect and exercise it over HTTP
go run ./cmd/swaig-test --url http://localhost:3001/simple --list-tools
go run ./cmd/swaig-test --url http://localhost:3001/simple --dump-swml
go run ./cmd/swaig-test --url http://localhost:3001/simple --exec get_time

# Pass function arguments with --param key=value (repeatable):
go run ./cmd/swaig-test --url http://localhost:3001/simple --exec get_weather --param location=London

See the CLI Guide for the full flag set, including --example NAME to introspect a compiled example binary without HTTP.

Agent Features

  • Prompt Object Model (POM) -- structured prompt composition via PromptAddSection()
  • SWAIG tools -- define functions with DefineTool() that the AI calls mid-conversation, with native access to the call's media stack
  • Skills system -- add capabilities with one-liners: a.AddSkill("datetime", nil) (blank-import _ "github.com/signalwire/signalwire-go/v3/pkg/skills/all" once to register the built-ins so AddSkill can resolve them by name)
  • Contexts and steps -- structured multi-step workflows with navigation control
  • DataMap tools -- tools that execute on SignalWire's servers, calling REST APIs without your own webhook
  • Dynamic configuration -- per-request agent customization for multi-tenant deployments
  • Call flow control -- pre-answer, post-answer, and post-AI verb insertion
  • Prefab agents -- ready-to-use archetypes (InfoGatherer, Survey, FAQ, Receptionist, Concierge)
  • Multi-agent hosting -- serve multiple agents on a single server with AgentServer
  • SIP routing -- route SIP calls to agents based on usernames
  • Session state -- persistent conversation state with global data and post-prompt summaries
  • Security -- auto-generated basic auth, function-specific HMAC tokens, SSL support
  • Serverless -- deploy to AWS Lambda (pkg/lambda), Google Cloud Functions and CGI (pkg/serverless)

Agent Examples

The examples/ directory contains 40+ working examples:

Example What it demonstrates
simple_agent POM prompts, SWAIG tools, multilingual support, LLM tuning
contexts_demo Multi-persona workflow with context switching and step navigation
datamap_demo Server-side API tools without webhooks
skills_demo Loading built-in skills (datetime, math)
call_flow Call flow verbs, debug events, FunctionResult actions
session_state OnSummary, global data, post-prompt summaries
multi_agent_server Multiple agents on one server
lambda AWS Lambda deployment with AsRouter()
comprehensive_dynamic Per-request dynamic configuration, multi-tenant routing

See examples/README.md for the full list organized by category.


RELAY Client

Real-time call control and messaging over WebSocket. The RELAY client connects to SignalWire via the Blade protocol and gives you goroutine-safe, imperative control over live phone calls and SMS/MMS.

package main

import (
	"context"
	"fmt"
	"os"
	"time"

	"github.com/signalwire/signalwire-go/v3/pkg/relay"
)

func main() {
	client := relay.NewRelayClient(
		relay.WithProject(os.Getenv("SIGNALWIRE_PROJECT_ID")),
		relay.WithToken(os.Getenv("SIGNALWIRE_API_TOKEN")),
		relay.WithSpace(os.Getenv("SIGNALWIRE_SPACE")),
		relay.WithContexts("default"),
	)

	client.OnCall(func(call *relay.Call) {
		call.Answer()
		action := call.Play([]map[string]any{
			{"type": "tts", "params": map[string]any{"text": "Welcome to SignalWire!"}},
		})
		ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
		defer cancel()
		action.Wait(ctx)
		call.Hangup("")
	})

	fmt.Println("Waiting for inbound calls ...")
	client.Run()
}
  • 57+ calling methods (play, record, collect, detect, tap, stream, AI, conferencing, and more)
  • SMS/MMS messaging with delivery tracking
  • Action objects with Wait(), Stop(), Pause(), Resume()
  • Auto-reconnect with exponential backoff

See the RELAY documentation for the full guide, API reference, and examples.


REST Client

Synchronous REST client for managing SignalWire resources and controlling calls over HTTP. No WebSocket required.

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/signalwire/signalwire-go/v3/pkg/rest"
	"github.com/signalwire/signalwire-go/v3/pkg/rest/namespaces"
)

func main() {
	// Reads from SIGNALWIRE_PROJECT_ID, SIGNALWIRE_API_TOKEN, SIGNALWIRE_SPACE
	client, err := rest.NewRestClient("", "", "")
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		os.Exit(1)
	}

	client.Fabric.AIAgents.Create(context.Background(), map[string]any{
		"name":   "Support Bot",
		"prompt": map[string]any{"text": "You are helpful."},
	})

	client.Calling.Dial(context.Background(), namespaces.CallingNamespaceDialParams{
		From: "+15559876543",
		To:   "+15551234567",
		URL:  ptr("https://example.com/call-handler"),
	})

	results, _ := client.PhoneNumbers.Search(context.Background(), map[string]string{"areacode": "512"})
	fmt.Println(results)
}

// ptr returns a pointer to v, for setting optional pointer-typed params.
func ptr[T any](v T) *T { return &v }
  • 22 namespaced API surfaces: Fabric (16 sub-resources), Calling (37 commands), Video, Datasphere, Phone Numbers, SIP, Queues, Recordings, Messages, Projects, and more
  • Shared http.Client for connection pooling
  • Typed params and responses -- generated *Params structs and *Response wrapper types per operation (from the spec-driven REST generator)

See the REST documentation for the full guide, API reference, and examples.


Installation

go get github.com/signalwire/signalwire-go/v3

Requires Go 1.25 or later.

Documentation

Full reference documentation is available at developer.signalwire.com/sdks/agents-sdk.

Guides are also available in the docs/ directory:

Getting Started

  • Agent Guide -- creating agents, prompt configuration, dynamic setup
  • Architecture -- SDK architecture and core concepts
  • SDK Features -- feature overview, SDK vs raw SWML comparison

Core Features

Skills and Extensions

Deployment

Reference

Environment Variables

Your project ID, API token, and space are on the SignalWire Dashboard under API (or see Navigating your SignalWire Space). Create a SignalWire account first if you don't have one.

Variable Used by Description
SIGNALWIRE_PROJECT_ID RELAY, REST Project identifier
SIGNALWIRE_API_TOKEN RELAY, REST API token
SIGNALWIRE_SPACE RELAY, REST Space hostname (e.g. example.signalwire.com)
SWML_BASIC_AUTH_USER Agents Basic auth username (default: auto-generated)
SWML_BASIC_AUTH_PASSWORD Agents Basic auth password (default: auto-generated)
SWML_PROXY_URL_BASE Agents Base URL when behind a reverse proxy
SWML_SSL_ENABLED Agents Enable HTTPS (true, 1, yes)
SWML_SSL_CERT_PATH Agents Path to SSL certificate
SWML_SSL_KEY_PATH Agents Path to SSL private key
SWML_SSL_DOMAIN Agents Domain used for TLS certificate / URL generation
SWML_SKIP_SCHEMA_VALIDATION Agents Set truthy to skip SWML schema validation (true, 1, yes)
SIGNALWIRE_SIGNING_KEY Agents HMAC signing key for secure SWAIG function tokens
SIGNALWIRE_RELAY_HOST RELAY Override the RELAY WebSocket host
SIGNALWIRE_RELAY_SCHEME RELAY Override the RELAY WebSocket scheme (ws / wss)
SIGNALWIRE_JWT_TOKEN RELAY JWT auth token (alternative to project+token)
SIGNALWIRE_RELAY_CA_FILE RELAY Path to a PEM CA bundle to trust for the RELAY WebSocket TLS (private-CA convention)
SIGNALWIRE_REST_BASE_URL REST Override the REST API base URL
SIGNALWIRE_REST_CA_FILE REST Path to a PEM CA bundle to trust for REST HTTPS (private-CA convention)
SIGNALWIRE_SPACE_NAME Skills Space name for Datasphere serverless skills
SIGNALWIRE_API_TOKEN Skills API token for Datasphere serverless skills
SIGNALWIRE_LOG_LEVEL All Logging level (debug, info, warn, error)
SIGNALWIRE_LOG_MODE All Set to off to suppress all logging
SIGNALWIRE_MCP_ALLOW_INSECURE_TLS Skills (mcp_gateway) Second gate required to disable upstream TLS verification. The mcp_gateway skill verifies TLS by default (verify_ssl=true); setting verify_ssl=false alone is IGNORED (logged) unless this is ALSO set truthy (true, 1, yes). Leave unset in production.

Testing, linting, formatting

Format, lint, and test go through three canonical scripts under scripts/. They self-bootstrap their tool environment and run from the module root regardless of your current directory.

# Test — go test ./... (optional filter/package passthrough)
bash scripts/run-tests.sh
bash scripts/run-tests.sh ./pkg/agent/...
bash scripts/run-tests.sh -run TestFoo ./pkg/relay/...
bash scripts/run-tests.sh -coverprofile=coverage.out ./...   # raw go test flags pass through

# Lint — go vet + golangci-lint
bash scripts/run-lint.sh

# Format — gofmt (apply) / --check (verify-only)
bash scripts/run-format.sh
bash scripts/run-format.sh --check

# Everything (full gate set)
bash scripts/run-ci.sh

License

MIT -- see LICENSE for details.

About

SignalWire AI Agents Go SDK, Relay and REST

Resources

Code of conduct

Contributing

Security policy

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages