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
tac = TAC(config=TACConfig.from_env())
... setup connectors ...¶
server = TACAWSFastAPIServer( tac=tac, voice_channel=connector.voice, messaging_channels=[connector.sms], public_domain=os.getenv("TWILIO_VOICE_PUBLIC_DOMAIN") # e.g., "myapp.ngrok.app" )
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 TACServerConfig.public_domain, which reads from TWILIO_VOICE_PUBLIC_DOMAIN environment variable.
Example
from tac.server import TACServerConfig
Set TWILIO_VOICE_PUBLIC_DOMAIN=your-app.ngrok.app¶
server = TACAWSFastAPIServer( tac=tac, voice_channel=voice, messaging_channels=[sms], config=TACServerConfig.from_env() ) 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 (SMS) and WebSocket (Voice) protocols.
TACAgentCoreWebSocketAdapter ¶
TACAgentCoreWebSocketAdapter(
ws: Any,
welcome_message: str = "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.
TACAgentCoreApp ¶
TACAgentCoreApp(
tac: TAC,
voice_channel: VoiceChannel,
sms_channel: SMSChannel,
welcome_message: str = "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 (SMS) and WebSocket (Voice) protocols.