***

title: AgentBase
slug: /reference/typescript/agents/agent-base
description: The central class for building AI-powered voice agents with SignalWire.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

[ai]: /docs/swml/reference/ai

[swml-reference]: /docs/swml/reference/ai

[agentserver]: /docs/server-sdks/reference/typescript/agents/agent-server

[setnativefunctions]: /docs/server-sdks/reference/typescript/agents/agent-base/native-functions

[ref-datamap]: /docs/server-sdks/reference/typescript/agents/data-map

`AgentBase` is the central class in the SignalWire AI Agents SDK. It provides a
complete framework for building AI-powered voice agents, combining prompt management,
tool definitions, skill loading, speech configuration, and web serving into a single
composable interface.

`AgentBase` uses **composition** internally, assembling functionality from
`PromptManager`, `SwmlBuilder`, `SessionManager`, `ContextBuilder`, and `SkillManager`.
All setter methods return `this` for fluent method chaining.

<Info>
  AgentBase generates a SWML document with the [`ai`][ai] verb.
  See the [SWML reference][swml-reference] for the full specification of all
  supported parameters and behaviors.
</Info>

## **Constructor**

```typescript {3}
import { AgentBase } from '@signalwire/sdk';

const agent = new AgentBase({
  name: 'support',
  route: '/support',
});
```

### Constructor Parameters

<ParamField path="name" type="string" required={true} toc={true}>
  Display name of the agent. Used in logging, SIP username mapping, and the default
  prompt fallback.
</ParamField>

<ParamField path="route" type="string" default="/" toc={true}>
  HTTP route path where this agent is served. Used by
  [`AgentServer`][agentserver] when hosting multiple agents on one process.
</ParamField>

<ParamField path="host" type="string" default="0.0.0.0" toc={true}>
  Network interface the HTTP server binds to.
</ParamField>

<ParamField path="port" type="number" toc={true}>
  Port the HTTP server listens on. Defaults to the `PORT` environment variable,
  falling back to `3000`.
</ParamField>

<ParamField path="basicAuth" type="[string, string]" toc={true}>
  Explicit `[username, password]` tuple for HTTP Basic Auth on all endpoints. If not
  set, credentials are read from `SWML_BASIC_AUTH_USER` / `SWML_BASIC_AUTH_PASSWORD`
  env vars, or auto-generated on startup.
</ParamField>

<ParamField path="usePom" type="boolean" default="true" toc={true}>
  Enable Prompt Object Model for structured prompt building. Set to `false` to use
  plain text prompts only.
</ParamField>

<ParamField path="tokenExpirySecs" type="number" default="900" toc={true}>
  Expiration time in seconds for SWAIG function authentication tokens.
</ParamField>

<ParamField path="autoAnswer" type="boolean" default="true" toc={true}>
  Automatically add an `answer` verb before the AI verb in the SWML document.
</ParamField>

<ParamField path="recordCall" type="boolean" default="false" toc={true}>
  Enable call recording. When `true`, a `record_call` verb is added to the SWML document.
</ParamField>

<ParamField path="recordFormat" type="string" default="mp4" toc={true}>
  Recording file format. Common values: `"mp4"`, `"wav"`.
</ParamField>

<ParamField path="recordStereo" type="boolean" default="true" toc={true}>
  Record in stereo (separate channels for each party) when `true`.
</ParamField>

<ParamField path="defaultWebhookUrl" type="string" toc={true}>
  Base URL for SWAIG function webhooks. If not set, the SDK auto-detects from the
  incoming request or uses `SWML_PROXY_URL_BASE`.
</ParamField>

<ParamField path="nativeFunctions" type="string[]" toc={true}>
  List of native SWAIG function names to enable at construction time (e.g.,
  `["check_time", "wait_for_user"]`). Can also be set later via
  [`setNativeFunctions()`][setnativefunctions].
</ParamField>

<ParamField path="agentId" type="string" toc={true}>
  Unique identifier for this agent instance. Auto-generated as a random hex string
  if not provided.
</ParamField>

<ParamField path="suppressLogs" type="boolean" toc={true}>
  Suppress SDK log output. Useful in testing or when integrating with external logging.
</ParamField>

## **Properties**

<ParamField path="name" type="string" toc={true}>
  The agent's display name. Set at construction time.
</ParamField>

<ParamField path="route" type="string" toc={true}>
  HTTP route path where this agent is served.
</ParamField>

<ParamField path="host" type="string" toc={true}>
  Network interface the HTTP server binds to.
</ParamField>

<ParamField path="port" type="number" toc={true}>
  Port the HTTP server listens on.
</ParamField>

<ParamField path="agentId" type="string" toc={true}>
  Unique identifier for this agent instance.
</ParamField>

## **Static Members**

<ParamField path="PROMPT_SECTIONS" type="Array<{ title: string; body?: string; bullets?: string[]; numbered?: boolean }>" toc={true}>
  Class-level attribute. Subclasses can set this to declaratively define prompt sections
  instead of calling `promptAddSection()` in the constructor.
</ParamField>

## **Examples**

### Basic agent with a tool

```typescript {3}
import { AgentBase, FunctionResult } from '@signalwire/sdk';

const agent = new AgentBase({ name: 'support-agent', route: '/support' });

agent.addLanguage({ name: 'English', code: 'en-US', voice: 'rime.spore' });
agent.setPromptText('You are a friendly customer support agent.');
agent.addHints(['SignalWire', 'SWML', 'SWAIG']);
agent.setParams({ temperature: 0.7, end_of_speech_timeout: 1000 });

agent.defineTool({
  name: 'check_order',
  description: 'Look up the status of a customer order',
  parameters: {
    type: 'object',
    properties: {
      order_id: { type: 'string', description: 'The order ID to look up' },
    },
  },
  required: ['order_id'],
  handler: async (args) => {
    const orderId = args.order_id;
    return new FunctionResult(`Order ${orderId} shipped on March 28.`);
  },
});

await agent.run();
```

### Subclass with declarative prompt sections

```typescript {3}
import { AgentBase, FunctionResult } from '@signalwire/sdk';

class SupportAgent extends AgentBase {
  static override PROMPT_SECTIONS = [
    {
      title: 'Role',
      body: 'You are a customer support agent for Acme Corp.',
    },
    {
      title: 'Guidelines',
      bullets: ['Be polite and professional', 'Escalate billing disputes'],
    },
  ];

  protected override defineTools(): void {
    this.defineTool({
      name: 'transfer_call',
      description: 'Transfer the caller to a live agent',
      handler: async () => {
        return new FunctionResult('Transferring now.').connect('+15551234567');
      },
    });
  }
}

const agent = new SupportAgent({ name: 'support', route: '/support' });
await agent.run();
```

## **Methods**

<CardGroup cols={3}>
  <Card title="addAnswerVerb" href="/docs/server-sdks/reference/typescript/agents/agent-base/add-answer-verb">
    Configure the answer verb that connects the call.
  </Card>

  <Card title="addFunctionInclude" href="/docs/server-sdks/reference/typescript/agents/agent-base/add-function-include">
    Add a remote function include to the SWAIG configuration.
  </Card>

  <Card title="addHint" href="/docs/server-sdks/reference/typescript/agents/agent-base/add-hint">
    Add a single speech recognition hint to improve transcription accuracy.
  </Card>

  <Card title="addHints" href="/docs/server-sdks/reference/typescript/agents/agent-base/add-hints">
    Add multiple speech recognition hints at once.
  </Card>

  <Card title="addInternalFiller" href="/docs/server-sdks/reference/typescript/agents/agent-base/add-internal-filler">
    Add filler phrases for a specific function and language.
  </Card>

  <Card title="addLanguage" href="/docs/server-sdks/reference/typescript/agents/agent-base/add-language">
    Add a language configuration with voice settings for multilingual conversations.
  </Card>

  <Card title="addMcpServer" href="/docs/server-sdks/reference/typescript/agents/agent-base/add-mcp-server">
    Add an external MCP server for tool discovery and invocation.
  </Card>

  <Card title="addPatternHint" href="/docs/server-sdks/reference/typescript/agents/agent-base/add-pattern-hint">
    Add a speech recognition hint with pattern matching and replacement.
  </Card>

  <Card title="addPostAiVerb" href="/docs/server-sdks/reference/typescript/agents/agent-base/add-post-ai-verb">
    Add a SWML verb to run after the AI conversation ends.
  </Card>

  <Card title="addPostAnswerVerb" href="/docs/server-sdks/reference/typescript/agents/agent-base/add-post-answer-verb">
    Add a SWML verb to run after the call is answered but before the AI starts.
  </Card>

  <Card title="addPreAnswerVerb" href="/docs/server-sdks/reference/typescript/agents/agent-base/add-pre-answer-verb">
    Add a SWML verb to run before the call is answered.
  </Card>

  <Card title="addPronunciation" href="/docs/server-sdks/reference/typescript/agents/agent-base/add-pronunciation">
    Add a pronunciation rule to correct how the AI speaks a specific word or phrase.
  </Card>

  <Card title="addSkill" href="/docs/server-sdks/reference/typescript/agents/agent-base/add-skill">
    Load and activate a skill on the agent.
  </Card>

  <Card title="addSwaigQueryParams" href="/docs/server-sdks/reference/typescript/agents/agent-base/add-swaig-query-params">
    Append query parameters to all SWAIG webhook URLs.
  </Card>

  <Card title="asRouter" href="/docs/server-sdks/reference/typescript/agents/agent-base/as-router">
    Get the agent's Hono app for mounting as a sub-router.
  </Card>

  <Card title="clearPostAiVerbs" href="/docs/server-sdks/reference/typescript/agents/agent-base/clear-post-ai-verbs">
    Remove all post-AI verbs from the call flow.
  </Card>

  <Card title="clearPostAnswerVerbs" href="/docs/server-sdks/reference/typescript/agents/agent-base/clear-post-answer-verbs">
    Remove all post-answer verbs from the call flow.
  </Card>

  <Card title="clearPreAnswerVerbs" href="/docs/server-sdks/reference/typescript/agents/agent-base/clear-pre-answer-verbs">
    Remove all pre-answer verbs from the call flow.
  </Card>

  <Card title="defineContexts" href="/docs/server-sdks/reference/typescript/agents/agent-base/define-contexts">
    Define multi-step conversation contexts and workflows.
  </Card>

  <Card title="defineTool" href="/docs/server-sdks/reference/typescript/agents/agent-base/define-tool">
    Define a SWAIG tool that the AI can invoke during conversations.
  </Card>

  <Card title="defineTypedTool" href="/docs/server-sdks/reference/typescript/agents/agent-base/define-typed-tool">
    Define a tool with a typed handler and automatic schema inference.
  </Card>

  <Card title="defineTools" href="/docs/server-sdks/reference/typescript/agents/agent-base/define-tools">
    Override hook that registers tools during construction.
  </Card>

  <Card title="enableDebugEvents" href="/docs/server-sdks/reference/typescript/agents/agent-base/enable-debug-events">
    Enable real-time debug event webhooks from the AI module during calls.
  </Card>

  <Card title="enableMcpServer" href="/docs/server-sdks/reference/typescript/agents/agent-base/enable-mcp-server">
    Expose the agent's tools as an MCP server endpoint.
  </Card>

  <Card title="enableSipRouting" href="/docs/server-sdks/reference/typescript/agents/agent-base/enable-sip-routing">
    Enable SIP-based call routing for this agent.
  </Card>

  <Card title="extractSipUsername" href="/docs/server-sdks/reference/typescript/agents/agent-base/extract-sip-username">
    Extract a SIP username from a request body (static method).
  </Card>

  <Card title="getApp" href="/docs/server-sdks/reference/typescript/agents/agent-base/get-app">
    Get the Hono application instance.
  </Card>

  <Card title="getBasicAuthCredentials" href="/docs/server-sdks/reference/typescript/agents/agent-base/get-basic-auth-credentials">
    Retrieve the agent's Basic Auth credentials and their origin.
  </Card>

  <Card title="getFullUrl" href="/docs/server-sdks/reference/typescript/agents/agent-base/get-full-url">
    Get the full URL for this agent's endpoint.
  </Card>

  <Card title="getMcpServers" href="/docs/server-sdks/reference/typescript/agents/agent-base/get-mcp-servers">
    Get the list of configured MCP servers.
  </Card>

  <Card title="getName" href="/docs/server-sdks/reference/typescript/agents/agent-base/get-name">
    Get the agent's display name.
  </Card>

  <Card title="getPostPrompt" href="/docs/server-sdks/reference/typescript/agents/agent-base/get-post-prompt">
    Retrieve the current post-prompt text.
  </Card>

  <Card title="getPrompt" href="/docs/server-sdks/reference/typescript/agents/agent-base/get-prompt">
    Retrieve the current rendered prompt text.
  </Card>

  <Card title="getRegisteredTools" href="/docs/server-sdks/reference/typescript/agents/agent-base/get-registered-tools">
    Get summaries of all registered tools.
  </Card>

  <Card title="getTool" href="/docs/server-sdks/reference/typescript/agents/agent-base/get-tool">
    Look up a registered tool by name.
  </Card>

  <Card title="handleMcpRequest" href="/docs/server-sdks/reference/typescript/agents/agent-base/handle-mcp-request">
    Handle an MCP JSON-RPC 2.0 request.
  </Card>

  <Card title="hasSkill" href="/docs/server-sdks/reference/typescript/agents/agent-base/has-skill">
    Check whether a specific skill is currently loaded.
  </Card>

  <Card title="isMcpServerEnabled" href="/docs/server-sdks/reference/typescript/agents/agent-base/is-mcp-server-enabled">
    Check if the MCP server endpoint is enabled.
  </Card>

  <Card title="listSkills" href="/docs/server-sdks/reference/typescript/agents/agent-base/list-skills">
    List all currently loaded skills.
  </Card>

  <Card title="manualSetProxyUrl" href="/docs/server-sdks/reference/typescript/agents/agent-base/manual-set-proxy-url">
    Manually set the proxy URL base for webhook callbacks.
  </Card>

  <Card title="setNativeFunctions" href="/docs/server-sdks/reference/typescript/agents/agent-base/native-functions">
    Set the list of native platform functions.
  </Card>

  <Card title="onDebugEvent" href="/docs/server-sdks/reference/typescript/agents/agent-base/on-debug-event">
    Lifecycle hook for debug events received at /debug\_events.
  </Card>

  <Card title="onFunctionCall" href="/docs/server-sdks/reference/typescript/agents/agent-base/on-function-call">
    Pre-execution hook called before each SWAIG function invocation.
  </Card>

  <Card title="onSummary" href="/docs/server-sdks/reference/typescript/agents/agent-base/on-summary">
    Handle post-prompt summaries generated after a conversation ends.
  </Card>

  <Card title="onSwmlRequest" href="/docs/server-sdks/reference/typescript/agents/agent-base/on-swml-request">
    Lifecycle hook called on every SWML request before rendering.
  </Card>

  <Card title="promptAddSection" href="/docs/server-sdks/reference/typescript/agents/agent-base/prompt-add-section">
    Add a new section to the agent's structured prompt.
  </Card>

  <Card title="promptAddSubsection" href="/docs/server-sdks/reference/typescript/agents/agent-base/prompt-add-subsection">
    Add a subsection to an existing prompt section.
  </Card>

  <Card title="promptAddToSection" href="/docs/server-sdks/reference/typescript/agents/agent-base/prompt-add-to-section">
    Append content to an existing prompt section.
  </Card>

  <Card title="promptHasSection" href="/docs/server-sdks/reference/typescript/agents/agent-base/prompt-has-section">
    Check whether a named section exists in the agent's prompt.
  </Card>

  <Card title="registerSipUsername" href="/docs/server-sdks/reference/typescript/agents/agent-base/register-sip-username">
    Register a SIP username to route calls to this agent.
  </Card>

  <Card title="registerSwaigFunction" href="/docs/server-sdks/reference/typescript/agents/agent-base/register-swaig-function">
    Register a raw SWAIG function descriptor, typically from a DataMap.
  </Card>

  <Card title="removeSkill" href="/docs/server-sdks/reference/typescript/agents/agent-base/remove-skill">
    Unload a skill from the agent.
  </Card>

  <Card title="renderSwml" href="/docs/server-sdks/reference/typescript/agents/agent-base/render-swml">
    Render the complete SWML document.
  </Card>

  <Card title="run" href="/docs/server-sdks/reference/typescript/agents/agent-base/run">
    Start the HTTP server (alias for serve).
  </Card>

  <Card title="serve" href="/docs/server-sdks/reference/typescript/agents/agent-base/serve">
    Start the Hono HTTP server to serve SWML and SWAIG endpoints.
  </Card>

  <Card title="setDynamicConfigCallback" href="/docs/server-sdks/reference/typescript/agents/agent-base/set-dynamic-config-callback">
    Set a callback for per-request dynamic agent configuration.
  </Card>

  <Card title="setGlobalData" href="/docs/server-sdks/reference/typescript/agents/agent-base/set-global-data">
    Replace the global data object available to the AI.
  </Card>

  <Card title="setLanguages" href="/docs/server-sdks/reference/typescript/agents/agent-base/set-languages">
    Replace all language configurations at once.
  </Card>

  <Card title="setParam" href="/docs/server-sdks/reference/typescript/agents/agent-base/set-param">
    Set a single AI parameter by key.
  </Card>

  <Card title="setParams" href="/docs/server-sdks/reference/typescript/agents/agent-base/set-params">
    Configure AI model parameters such as temperature and timeouts.
  </Card>

  <Card title="setPostPrompt" href="/docs/server-sdks/reference/typescript/agents/agent-base/set-post-prompt">
    Set the post-prompt for generating call summaries.
  </Card>

  <Card title="setPostPromptLlmParams" href="/docs/server-sdks/reference/typescript/agents/agent-base/set-post-prompt-llm-params">
    Set LLM parameters for the post-prompt.
  </Card>

  <Card title="setPostPromptUrl" href="/docs/server-sdks/reference/typescript/agents/agent-base/set-post-prompt-url">
    Override the URL where post-prompt summaries are delivered.
  </Card>

  <Card title="setPromptLlmParams" href="/docs/server-sdks/reference/typescript/agents/agent-base/set-prompt-llm-params">
    Set LLM parameters for the main prompt.
  </Card>

  <Card title="setPromptText" href="/docs/server-sdks/reference/typescript/agents/agent-base/set-prompt-text">
    Set the agent's system prompt as raw text.
  </Card>

  <Card title="setupGracefulShutdown" href="/docs/server-sdks/reference/typescript/agents/agent-base/setup-graceful-shutdown">
    Register signal handlers for graceful shutdown (static method).
  </Card>

  <Card title="setWebHookUrl" href="/docs/server-sdks/reference/typescript/agents/agent-base/set-web-hook-url">
    Override the default webhook URL for SWAIG function calls.
  </Card>

  <Card title="updateGlobalData" href="/docs/server-sdks/reference/typescript/agents/agent-base/update-global-data">
    Merge data into the global data object.
  </Card>

  <Card title="validateBasicAuth" href="/docs/server-sdks/reference/typescript/agents/agent-base/validate-basic-auth">
    Custom basic-auth validation hook.
  </Card>
</CardGroup>