Skip to content

Server

Server utilities for running TAC on AWS. Requires the server extra; the AgentCore app additionally requires the agentcore extra.

FastAPI Server

tac_aws.server.fastapi_server

AWS-specific FastAPI server wrapper for TAC.

This module provides TACAWSFastAPIServer which extends TACFastAPIServer with middleware to handle AWS ALB deployments. AWS ALB does not set X-Forwarded-Host header, which causes Twilio signature validation to fail when using ngrok for testing.

Usage

from tac import TAC from tac.core.config import TACConfig from tac_aws.server import TACAWSFastAPIServer

TWILIO_VOICE_PUBLIC_DOMAIN (e.g. "myapp.ngrok.app") feeds

TACConfig.voice_public_domain, which this server reads for the ALB fix.

tac = TAC(config=TACConfig.from_env())

... setup connectors ...

server = TACAWSFastAPIServer( tac=tac, voice_channel=connector.voice, messaging_channels=[connector.sms], )

if name == "main": server.start()

TACAWSFastAPIServer

TACAWSFastAPIServer(tac: TAC, voice_channel: VoiceChannel | None = None, messaging_channels: list[MessagingChannel] | None = None, config: TACServerConfig | None = None, app: FastAPI | None = None)

Bases: TACFastAPIServer

AWS-specific FastAPI server for TAC with proxy header handling.

This extends TACFastAPIServer by adding middleware to ensure X-Forwarded-Host and X-Forwarded-Proto headers are set correctly for Twilio signature validation.

Required for AWS ALB deployments where ALB doesn't set X-Forwarded-Host, but also safe to use for local development with ngrok.

The public domain is automatically obtained from TACConfig.voice_public_domain, which reads from the TWILIO_VOICE_PUBLIC_DOMAIN environment variable.

Example

Set TWILIO_VOICE_PUBLIC_DOMAIN=your-app.ngrok.app

tac = TAC(config=TACConfig.from_env()) server = TACAWSFastAPIServer( tac=tac, voice_channel=voice, messaging_channels=[sms], ) server.start()

Initialize the AWS FastAPI server.

Parameters:

Name Type Description Default
tac TAC

The TAC instance.

required
voice_channel VoiceChannel | None

Optional voice channel (WebSocket).

None
messaging_channels list[MessagingChannel] | None

Optional list of messaging channels (SMS, WhatsApp, etc).

None
config TACServerConfig | None

Optional TACServerConfig (if None, creates default config from env).

None
app FastAPI | None

Optional existing FastAPI app to wrap.

None

AgentCore App

tac_aws.server.agentcore_app

App adapter for TAC on AWS Bedrock AgentCore.

Integrates TAC channels with BedrockAgentCoreApp for serverless deployment. Handles both HTTP (messaging channels) and WebSocket (Voice) protocols.

TACAgentCoreWebSocketAdapter

TACAgentCoreWebSocketAdapter(ws: Any, welcome_message: str | None = 'Hello! How can I assist you today?')

WebSocket wrapper that sends a welcome greeting after setup.

Required for Twilio ConversationRelay with conversationConfiguration. Without an initial greeting, ConversationRelay won't activate speech detection.

A TwiML welcomeGreeting is not a substitute on AgentCore: Twilio plays it only after the WebSocket is established, and AgentCore defers that handshake until the per-session microVM boots (~6s for a fresh session vs ~0.3s once it exists). With one session per call, it never reaches the caller. This greeting works because it is sent after setup.

welcome_message=None skips it, leaving the call silent until the caller speaks.

TACAgentCoreApp

TACAgentCoreApp(tac: TAC, voice_channel: VoiceChannel, messaging_channels: Sequence[MessagingChannel] | MessagingChannel, welcome_message: str | None = 'Hello! How can I assist you today?')

App adapter for TAC on AWS Bedrock AgentCore.

Integrates TAC channels with BedrockAgentCoreApp for serverless deployment. Handles both HTTP (messaging channels) and WebSocket (Voice) protocols.

Parameters:

Name Type Description Default
tac TAC

TAC instance

required
voice_channel VoiceChannel

Voice channel handling the ConversationRelay WebSocket

required
messaging_channels Sequence[MessagingChannel] | MessagingChannel

Messaging channels handling forwarded conversation webhooks — SMS, RCS, WhatsApp, Chat, in any combination. Pass connector.channels.messaging to wire up everything the connector enabled. A single channel is accepted for convenience. Each webhook is offered to every channel; a channel ignores the ones that aren't its own, exactly as TACFastAPIServer does.

required
welcome_message str | None

Greeting spoken once the ConversationRelay session is set up. Keep it — a TwiML welcomeGreeting never reaches the caller on AgentCore; see TACAgentCoreWebSocketAdapter.

'Hello! How can I assist you today?'

run

run() -> None

Start the AgentCore app.