Skip to navigation

BedrockAgent

View as MarkdownOpen in Claude

BedrockAgent extends AgentBase to use Amazon Bedrock’s voice-to-voice model as the AI backend. It renders SWML with the amazon_bedrock verb instead of ai, and keeps every standard agent feature: text and POM prompts, skills, SWAIG functions, post-prompt, and dynamic configuration.

Extends AgentBase — inherits all parent properties and methods.

BedrockAgent generates SWML with the amazon_bedrock verb instead of ai. See the SWML bedrock reference for the full specification.

Constructor

import { BedrockAgent } from '@signalwire/sdk';
const agent = new BedrockAgent({
systemPrompt: 'You are a helpful voice assistant.',
voiceId: 'tiffany',
});

The createBedrockAgent(config) factory function returns the same instance as new BedrockAgent(config).

Constructor parameters

name
stringDefaults to bedrock_agent

Agent name.

route
stringDefaults to /bedrock

HTTP route for the agent endpoint.

systemPrompt
string

Initial system prompt, set as raw text. Can be overridden later with setPromptText(). Leave it unset if you build the prompt from sections with promptAddSection(), because raw text takes precedence over sections.

voiceId
stringDefaults to matthew

Bedrock voice identifier ("tiffany", "matthew", "amy", "lupe", or "carlos").

temperature
number | stringDefaults to 0.7

Generation temperature. Range: 0 to 2. A numeric string is converted, and a SWML variable reference such as '${temperature}' is kept; anything else throws.

topP
number | stringDefaults to 0.9

Nucleus sampling parameter. Range: 0 to 1. A numeric string is converted, and a SWML variable reference is kept; anything else throws.

maxTokens
number | stringDefaults to 1024

Maximum tokens to generate per response, an integer or a numeric string. Sent in the prompt as max_tokens, but the platform’s Bedrock session doesn’t apply it.

agentOptions
Partial<AgentOptions>

Additional AgentBase constructor options (e.g., host, port, basicAuth).

Methods

Overridden behavior

BedrockAgent overrides several AgentBase methods to fit the Bedrock voice-to-voice model:

MethodBehavior
setLlmModel()Logs a warning and does nothing. Bedrock uses a fixed voice-to-voice model.
setLlmTemperature()Redirects to setInferenceParams(temperature).
setPromptLlmParams()temperature, top_p, and max_tokens update the inference settings, as setInferenceParams() does. Any other setting, such as confidence, presence_penalty, or barge_confidence, is ignored with a warning.
setPostPromptLlmParams()Logs a warning. The Bedrock post-prompt uses the LLM configured in the platform.

The amazon_bedrock verb carries the prompt, SWAIG functions, params, global data, and post-prompt settings. Speech hints, languages, pronunciation rules, multilingual settings, and contexts aren’t part of it, so they’re left out of the SWML, with one warning per agent for each. The platform’s Bedrock session reads only the prompt’s text, voice_id, temperature, and top_p.

Prompt methods (setPromptText(), setPromptPom(), promptAddSection(), and so on) work normally. The prompt is built the same way as in AgentBase and then placed in the amazon_bedrock verb, with voice_id, temperature, and top_p added to the prompt object itself. Raw text set through systemPrompt or setPromptText() takes precedence: when it is present, sections added with promptAddSection() are not rendered. Use one style or the other for a given agent.

Examples

Basic Bedrock agent with a tool

import { BedrockAgent, FunctionResult } from '@signalwire/sdk';
const agent = new BedrockAgent({
name: 'bedrock-assistant',
route: '/assistant',
voiceId: 'tiffany',
temperature: 0.5,
});
agent.promptAddSection('Role', { body: 'You are a helpful customer service representative.' });
agent.promptAddSection('Guidelines', { body: 'Be concise and professional.' });
agent.defineTool({
name: 'check_order',
description: 'Look up order status',
parameters: {
order_id: { type: 'string', description: 'Order ID' },
},
required: ['order_id'],
handler: async (args) => {
return new FunctionResult(`Order ${args.order_id} is shipped and arriving tomorrow.`);
},
});
agent.setVoice('matthew');
agent.setInferenceParams(0.3, 0.95);
await agent.run();

Multi-agent server with Bedrock

import { AgentBase, AgentServer, BedrockAgent } from '@signalwire/sdk';
// Standard agent
const standardAgent = new AgentBase({ name: 'standard', route: '/standard' });
standardAgent.setPromptText('You are a general assistant.');
// Bedrock voice-to-voice agent
const bedrockAgent = new BedrockAgent({
name: 'bedrock',
route: '/bedrock',
systemPrompt: 'You are a voice-optimized assistant.',
voiceId: 'matthew',
});
const server = new AgentServer();
server.register(standardAgent);
server.register(bedrockAgent);
await server.run();