AgentsAgentBase

add_per_call_config

View as MarkdownOpen in Claude

Register a per-request configuration callback, keeping any already registered. Same signature and contract as set_dynamic_config_callback(), except that callbacks accumulate instead of overwriting. They run in registration order against the same ephemeral agent, so a later callback sees what an earlier one configured and can build on or override it.

Prefer this form when composing. A base class and a subclass, or an agent and a mixin, can each register what they own without knowing about the other. With set_dynamic_config_callback() the second registration silently drops the first.

Parameters

callback
Callable[[dict[str, Any], dict[str, Any], dict[str, Any], Any], None]Required

A function with the signature (query_params, body_params, headers, agent). agent is the ephemeral per-request copy. Configure that object, never self, or the configuration leaks across callers.

Returns

AgentBase — Returns self for method chaining.

Example

from signalwire import AgentBase
agent = AgentBase(name="dispatch", route="/dispatch")
agent.set_prompt_text("You are Ada, the dispatcher for Bayview Taxi.")
def pick_language(query_params, body_params, headers, agent):
if query_params.get("lang") == "es":
agent.add_language("Spanish", "es-MX", "rime.marsh")
def tag_tenant(query_params, body_params, headers, agent):
agent.set_global_data({"tenant": query_params.get("tenant", "default")})
agent.add_per_call_config(pick_language)
agent.add_per_call_config(tag_tenant)
agent.serve()