AgentsAgentBase

set_dynamic_config_callback

View as MarkdownOpen in Claude

Set a callback function that runs on every incoming request, receiving an ephemeral copy of the agent so you can dynamically configure any aspect of it — skills, 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 passed to the callback is an ephemeral copy of the original agent. Changes made inside the callback apply only to the current request and do not persist across calls.

Parameters

callback
Callable[[dict, dict, dict, AgentBase], None]Required

A function with the signature (query_params, body_params, headers, agent). Use the agent argument to call any configuration method:

  • agent.add_skill(...)
  • agent.add_language(...)
  • agent.prompt_add_section(...)
  • agent.set_params(...)
  • agent.set_global_data(...)
  • agent.define_tool(...)

Returns

AgentBase — Returns self for method chaining.

Example

1from signalwire import AgentBase
2
3agent = AgentBase(name="assistant", route="/assistant")
4agent.set_prompt_text("You are a helpful assistant.")
5
6def configure_per_request(query_params, body_params, headers, agent):
7 tier = query_params.get("tier", "standard")
8 if tier == "premium":
9 agent.add_skill("web_search")
10 agent.set_params({"end_of_speech_timeout": 500})
11 agent.set_global_data({"tier": tier})
12
13agent.set_dynamic_config_callback(configure_per_request)
14agent.serve()