setDynamicConfigCallback

View as MarkdownOpen in Claude

Set a callback that runs on every incoming SWML request, receiving an ephemeral copy of the agent so you can dynamically configure any aspect of it — prompts, parameters, languages, tools, global data, etc. — based on the request’s query parameters, body, or headers.

This is the primary mechanism for multi-tenant or per-caller customization.

The agent argument is an ephemeral copy of the base agent — changes made inside the callback apply only to the current request and do not persist to the base agent or affect other requests.

Parameters

cb
DynamicConfigCallbackRequired

A function with the signature (queryParams: Record<string, string>, bodyParams: Record<string, unknown>, headers: Record<string, string>, agent: AgentBase) => void | Promise<void>. Use the agent argument to call any configuration method on the ephemeral copy.

Returns

AgentBase — Returns this for method chaining.

Example

1import { AgentBase } from '@signalwire/sdk';
2
3const agent = new AgentBase({ name: 'assistant', route: '/assistant' });
4agent.setPromptText('You are a helpful assistant.');
5
6agent.setDynamicConfigCallback(async (queryParams, bodyParams, headers, agentCopy) => {
7 const tier = queryParams.tier ?? 'standard';
8 if (tier === 'premium') {
9 agentCopy.setParams({ end_of_speech_timeout: 500 });
10 }
11 agentCopy.setGlobalData({ tier });
12});
13
14await agent.serve();