For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Log inSign up
Support
GuidesReference
GuidesReference
    • Core
      • Overview
    • Agents
      • Overview
      • AgentBase
        • add_answer_verb
        • add_function_include
        • add_hint
        • add_hints
        • add_internal_filler
        • add_language
        • add_mcp_server
        • add_pattern_hint
        • add_post_ai_verb
        • add_post_answer_verb
        • add_pre_answer_verb
        • add_pronunciation
        • add_skill
        • add_swaig_query_params
        • as_router
        • auto_map_sip_usernames
        • clear_post_ai_verbs
        • clear_post_answer_verbs
        • clear_pre_answer_verbs
        • clear_swaig_query_params
        • define_contexts
        • define_tool
        • define_tools
        • enable_debug_events
        • enable_debug_routes
        • enable_mcp_server
        • enable_sip_routing
        • get_app
        • get_basic_auth_credentials
        • get_full_url
        • get_name
        • get_post_prompt
        • get_prompt
        • handle_serverless_request
        • has_skill
        • list_skills
        • manual_set_proxy_url
        • on_debug_event
        • on_function_call
        • on_summary
        • on_swml_request
        • prompt_add_section
        • prompt_add_subsection
        • prompt_add_to_section
        • prompt_has_section
        • register_routing_callback
        • register_sip_username
        • register_swaig_function
        • remove_skill
        • reset_contexts
        • run
        • serve
        • set_dynamic_config_callback
        • set_function_includes
        • set_global_data
        • set_internal_fillers
        • set_languages
        • set_native_functions
        • set_param
        • set_params
        • set_post_prompt
        • set_post_prompt_llm_params
        • set_post_prompt_url
        • set_prompt_llm_params
        • set_prompt_pom
        • set_prompt_text
        • set_pronunciations
        • set_web_hook_url
        • setup_graceful_shutdown
        • update_global_data
        • validate_basic_auth
      • AgentServer
      • BedrockAgent
      • CLI Tools
      • Configuration
      • ContextBuilder
      • DataMap
      • FunctionResult
      • Helper Functions
      • LiveWire
      • MCP Gateway
      • PomBuilder
      • Prefabs
      • Search
      • SkillBase
      • Skills
      • SWAIGFunction
      • SWMLBuilder
      • SWMLService
      • WebService
    • RELAY
      • Overview
      • Actions
      • Call
      • Constants
      • Events
      • Message
      • RelayClient
      • RelayError
    • REST Client
      • Overview
      • Addresses
      • Calling
      • Chat
      • Compat
      • Datasphere
      • Fabric
      • Imported Numbers
      • Logs
      • Lookup
      • MFA
      • Number Groups
      • Phone Numbers
      • Project
      • PubSub
      • Queues
      • Recordings
      • Registry
      • RestClient
      • Short Codes
      • SignalWireRestError
      • SIP Profile
      • Verified Callers
      • Video
LogoLogoSignalWire Docs
Log inSign up
Support
On this page
  • Parameters
  • Returns
  • Example
AgentsAgentBase

on_swml_request

|View as Markdown|Open in Claude|
Was this page helpful?
Edit this page
Previous

prompt_add_section

Next
Built with

Customization point called during SWML rendering, before the document is returned to the caller. Override this method in a subclass to inspect request data and return modifications to apply to the SWML document.

The default implementation checks for a set_dynamic_config_callback() and, if one is registered, returns an internal marker that triggers ephemeral agent cloning. For most per-request customization, set_dynamic_config_callback() is the simpler approach.

This method is called during SWML rendering by the internal request handler. It is not an override of SWMLService.on_request() — it is a separate hook that adds support for dynamic configuration and ephemeral agent copies.

Parameters

request_data
Optional[dict[str, Any]]Defaults to None

Parsed POST body from the incoming request, if available.

callback_path
Optional[str]Defaults to None

The path segment that triggered this request.

request
Optional[Request]Defaults to None

The FastAPI Request object, providing access to query parameters, headers, and other HTTP metadata.

Returns

Optional[dict] — A dictionary of modifications to apply to the SWML document, or None for no modifications. The keys and structure depend on the rendering pipeline.

Example

1from signalwire import AgentBase
2
3class MultiTenantAgent(AgentBase):
4 def __init__(self):
5 super().__init__(name="multi-tenant", route="/agent")
6 self.set_prompt_text("You are a helpful assistant.")
7
8 def on_swml_request(self, request_data=None, callback_path=None, request=None):
9 """Inject tenant context into global_data based on a request header."""
10 tenant = None
11 if request:
12 tenant = request.headers.get("X-Tenant-ID")
13 if tenant:
14 # Return modifications — "global_data" keys are merged into ai.params.global_data
15 return {"global_data": {"tenant_id": tenant, "tier": "premium" if tenant == "acme" else "standard"}}
16 return super().on_swml_request(request_data, callback_path, request)
17
18agent = MultiTenantAgent()
19agent.run()

For most per-request customization scenarios, prefer set_dynamic_config_callback() which provides a higher-level interface with access to query params, body, headers, and the agent instance.