Connectors¶
Connectors combine AWS agent runtime integration with TAC channel management.
tac_aws.connectors ¶
Connectors for AWS agent integrations with TAC.
Connectors combine agent runtime integration with channel management and conversation handling.
BedrockAgentCoreConnector ¶
BedrockAgentCoreConnector(tac: TAC, runtime: RuntimeConfig | dict[str, Any], sms_config: SMSChannelConfig | dict[str, Any] | None = None, voice_config: VoiceChannelConfig | dict[str, Any] | None = None, rcs_config: RCSChannelConfig | dict[str, Any] | None = None, whatsapp_config: WhatsAppChannelConfig | dict[str, Any] | None = None, chat_config: ChatChannelConfig | dict[str, Any] | None = None)
Connector for AWS Bedrock Agent Core with dual-runtime pattern.
Provides two runtime modes:
- HTTP invocation (required): For both voice and SMS channels
- WebSocket streaming (optional): For voice channel low-latency optimization (~50ms vs ~200ms)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tac
|
TAC
|
TAC instance for channel integration |
required |
runtime
|
RuntimeConfig | dict[str, Any]
|
Agent runtime configuration (RuntimeConfig or dict):
|
required |
sms_config
|
SMSChannelConfig | dict[str, Any] | None
|
Optional SMS channel configuration (SMSChannelConfig or dict) |
None
|
voice_config
|
VoiceChannelConfig | dict[str, Any] | None
|
Optional Voice channel configuration (VoiceChannelConfig or dict) |
None
|
rcs_config
|
RCSChannelConfig | dict[str, Any] | None
|
Optional RCS channel tuning (RCSChannelConfig or dict). RCS
itself is enabled by setting |
None
|
whatsapp_config
|
WhatsAppChannelConfig | dict[str, Any] | None
|
Optional WhatsApp channel tuning (WhatsAppChannelConfig
or dict). WhatsApp itself is enabled by setting |
None
|
chat_config
|
ChatChannelConfig | dict[str, Any] | None
|
Optional Chat channel configuration (ChatChannelConfig or dict) |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
channels |
The full |
|
voice |
VoiceChannel instance for voice conversations |
|
sms |
SMSChannel instance for SMS conversations |
|
chat |
ChatChannel instance for web chat conversations |
|
rcs |
RCSChannel, or None when no RCS sender ID is configured |
|
whatsapp |
WhatsAppChannel, or None when no WhatsApp number is configured |
Example
import boto3
import json
import websockets
from bedrock_agentcore.runtime import AgentCoreRuntimeClient
from tac import TAC, TACConfig
from tac.models.session import ConversationSession
from tac.channels.sms import SMSChannelConfig
from tac.channels.voice import VoiceChannelConfig
from tac.server import TACFastAPIServer
from tac.session import ThreadSafeSessionManager
from tac_aws.connectors import BedrockAgentCoreConnector
from tac_aws.connectors.bedrock_agentcore.config import RuntimeConfig, WebSocketConfig
from websockets.client import WebSocketClientProtocol
tac = TAC(config=TACConfig.from_env())
AGENT_ARN = "arn:aws:bedrock-agentcore:us-east-1:123456789:agent-runtime/..."
# HTTP: boto3 client provides invoke_agent_runtime()
agentcore_http_client = boto3.client("bedrock-agentcore", region_name="us-east-1")
def invoke_agent_http(
context: ConversationSession,
user_message: str,
memory_context: str | None
) -> dict:
payload_data = {"prompt": user_message}
if memory_context:
payload_data["memory_context"] = memory_context
payload = json.dumps(payload_data).encode("utf-8")
return agentcore_http_client.invoke_agent_runtime(
agentRuntimeArn=AGENT_ARN,
runtimeSessionId=context.conversation_id,
payload=payload,
)
# WebSocket: AgentCoreRuntimeClient provides generate_ws_connection()
agentcore_client = AgentCoreRuntimeClient(region="us-east-1")
async def create_websocket(context: ConversationSession) -> WebSocketClientProtocol:
ws_url, headers = agentcore_client.generate_ws_connection(
runtime_arn=AGENT_ARN,
session_id=context.conversation_id,
)
return await websockets.connect(ws_url, additional_headers=headers)
def build_websocket_payload(
context: ConversationSession, user_message: str, memory_context: str | None
) -> dict[str, Any]:
payload: dict[str, Any] = {"type": "prompt", "voicePrompt": user_message}
if memory_context:
payload["memoryContext"] = memory_context
return payload
# Create connector
connector = BedrockAgentCoreConnector(
tac=tac,
runtime=RuntimeConfig(
http=invoke_agent_http, # Required: HTTP streaming for both channels
websocket=WebSocketConfig( # Optional: WebSocket optimization for voice
factory=create_websocket,
payload_fn=build_websocket_payload,
),
),
voice_config=VoiceChannelConfig(
session_manager=ThreadSafeSessionManager(),
memory_mode="once",
),
sms_config=SMSChannelConfig(memory_mode="always"),
)
# Use connector's channels for server
server = TACFastAPIServer(
tac=tac,
voice_channel=connector.voice,
messaging_channels=connector.channels.messaging,
)
server.start()
Initialize Bedrock Agent Core connector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tac
|
TAC
|
TAC instance |
required |
runtime
|
RuntimeConfig | dict[str, Any]
|
Agent runtime configuration (RuntimeConfig or dict) |
required |
sms_config
|
SMSChannelConfig | dict[str, Any] | None
|
Optional SMS channel configuration |
None
|
voice_config
|
VoiceChannelConfig | dict[str, Any] | None
|
Optional Voice channel configuration |
None
|
rcs_config
|
RCSChannelConfig | dict[str, Any] | None
|
Optional RCS channel tuning; TWILIO_RCS_SENDER_ID enables RCS |
None
|
whatsapp_config
|
WhatsAppChannelConfig | dict[str, Any] | None
|
Optional WhatsApp channel tuning; TWILIO_WHATSAPP_NUMBER enables WhatsApp |
None
|
chat_config
|
ChatChannelConfig | dict[str, Any] | None
|
Optional Chat channel configuration |
None
|
BedrockConnector ¶
BedrockConnector(tac: TAC, bedrock_client: AgentsforBedrockRuntimeClient | None = None, config: InvokeAgentRequestTypeDef | dict[str, Any] | None = None, invoke_fn: Callable[[ConversationSession, str, str | None], InvokeAgentResponseTypeDef] | None = None, sms_config: SMSChannelConfig | dict[str, Any] | None = None, voice_config: VoiceChannelConfig | dict[str, Any] | None = None, rcs_config: RCSChannelConfig | dict[str, Any] | None = None, whatsapp_config: WhatsAppChannelConfig | dict[str, Any] | None = None, chat_config: ChatChannelConfig | dict[str, Any] | None = None)
Connector for AWS Bedrock Agents with multi-channel support.
Supports two usage patterns:
- Simple config-based (recommended for most users)
- Custom invoke function (for advanced use cases needing dynamic behavior)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tac
|
TAC
|
TAC instance for channel integration |
required |
bedrock_client
|
AgentsforBedrockRuntimeClient | None
|
AWS Bedrock Agent Runtime client (required if using config) |
None
|
config
|
InvokeAgentRequestTypeDef | dict[str, Any] | None
|
Static configuration dict for invoke_agent() call (InvokeAgentRequestTypeDef). Required fields agentId, agentAliasId will be used. sessionId and inputText are auto-injected by connector. (required if using config pattern) |
None
|
invoke_fn
|
Callable[[ConversationSession, str, str | None], InvokeAgentResponseTypeDef] | None
|
Custom function to invoke agent. Receives:
Returns: InvokeAgentResponseTypeDef from client.invoke_agent() (required if not using config pattern) |
None
|
sms_config
|
SMSChannelConfig | dict[str, Any] | None
|
Optional SMS channel configuration (SMSChannelConfig or dict) |
None
|
voice_config
|
VoiceChannelConfig | dict[str, Any] | None
|
Optional Voice channel configuration (VoiceChannelConfig or dict) |
None
|
rcs_config
|
RCSChannelConfig | dict[str, Any] | None
|
Optional RCS channel tuning (RCSChannelConfig or dict). RCS
itself is enabled by setting |
None
|
whatsapp_config
|
WhatsAppChannelConfig | dict[str, Any] | None
|
Optional WhatsApp channel tuning (WhatsAppChannelConfig
or dict). WhatsApp itself is enabled by setting |
None
|
chat_config
|
ChatChannelConfig | dict[str, Any] | None
|
Optional Chat channel configuration (ChatChannelConfig or dict) |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
channels |
The full |
|
voice |
VoiceChannel instance for voice conversations |
|
sms |
SMSChannel instance for SMS conversations |
|
chat |
ChatChannel instance for web chat conversations |
|
rcs |
RCSChannel, or None when no RCS sender ID is configured |
|
whatsapp |
WhatsAppChannel, or None when no WhatsApp number is configured |
Example (Simple - Recommended):
import boto3
from tac import TAC, TACConfig
from tac.server import TACFastAPIServer
from tac_aws.connectors import BedrockConnector
tac = TAC(config=TACConfig.from_env())
client = boto3.client("bedrock-agent-runtime", region_name="us-east-1")
# Simple config-based approach
connector = BedrockConnector(
tac=tac,
bedrock_client=client,
config={
"agentId": "AGENT123",
"agentAliasId": "TSTALIASID",
"enableTrace": False, # Optional parameters
}
)
server = TACFastAPIServer(
tac=tac,
voice_channel=connector.voice,
messaging_channels=connector.channels.messaging,
)
server.start()
Example (Advanced - Custom Logic):
import boto3
from tac import TAC, TACConfig
from tac.models.session import ConversationSession
from tac.server import TACFastAPIServer
from tac_aws.connectors import BedrockConnector
tac = TAC(config=TACConfig.from_env())
client = boto3.client("bedrock-agent-runtime", region_name="us-east-1")
# Custom invoke function for dynamic behavior
def invoke_agent(
context: ConversationSession,
user_message: str,
memory_context: str | None
):
# Dynamic agent selection based on channel
agent_id = "VOICE_AGENT" if context.channel == "VOICE" else "SMS_AGENT"
full_message = user_message
if memory_context:
full_message = f"{memory_context}\n\nUser: {user_message}"
return client.invoke_agent(
agentId=agent_id,
agentAliasId="TSTALIASID",
sessionId=context.conversation_id,
inputText=full_message
)
connector = BedrockConnector(tac=tac, invoke_fn=invoke_agent)
server = TACFastAPIServer(
tac=tac,
voice_channel=connector.voice,
messaging_channels=connector.channels.messaging,
)
server.start()
Initialize Bedrock Agent connector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tac
|
TAC
|
TAC instance |
required |
bedrock_client
|
AgentsforBedrockRuntimeClient | None
|
AWS Bedrock Agent Runtime client (required if using config) |
None
|
config
|
InvokeAgentRequestTypeDef | dict[str, Any] | None
|
Static invoke_agent config dict (required if using config pattern) |
None
|
invoke_fn
|
Callable[[ConversationSession, str, str | None], InvokeAgentResponseTypeDef] | None
|
Custom invoke function (required if not using config pattern) |
None
|
sms_config
|
SMSChannelConfig | dict[str, Any] | None
|
Optional SMS channel configuration |
None
|
voice_config
|
VoiceChannelConfig | dict[str, Any] | None
|
Optional Voice channel configuration |
None
|
rcs_config
|
RCSChannelConfig | dict[str, Any] | None
|
Optional RCS channel tuning; TWILIO_RCS_SENDER_ID enables RCS |
None
|
whatsapp_config
|
WhatsAppChannelConfig | dict[str, Any] | None
|
Optional WhatsApp channel tuning; TWILIO_WHATSAPP_NUMBER enables WhatsApp |
None
|
chat_config
|
ChatChannelConfig | dict[str, Any] | None
|
Optional Chat channel configuration |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If both invoke_fn and config are provided, or neither are provided |
StrandsConnector ¶
StrandsConnector(tac: TAC, agent_factory: Callable[[ConversationSession], Agent], sms_config: SMSChannelConfig | dict[str, Any] | None = None, voice_config: VoiceChannelConfig | dict[str, Any] | None = None, rcs_config: RCSChannelConfig | dict[str, Any] | None = None, whatsapp_config: WhatsAppChannelConfig | dict[str, Any] | None = None, chat_config: ChatChannelConfig | dict[str, Any] | None = None)
Connector for AWS Strands SDK with multi-channel support.
Combines agent management with channel handling:
- Creates one Strands agent instance per conversation for proper isolation
- Manages every channel TAC supports — Voice, SMS, RCS, WhatsApp, and Chat
- Handles memory injection and message routing
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tac
|
TAC
|
TAC instance for channel integration |
required |
agent_factory
|
Callable[[ConversationSession], Agent]
|
Factory function that creates a new Agent instance. Receives ConversationSession context to enable SessionManager usage and context-aware agent configuration. |
required |
sms_config
|
SMSChannelConfig | dict[str, Any] | None
|
Optional SMS channel configuration (SMSChannelConfig or dict) |
None
|
voice_config
|
VoiceChannelConfig | dict[str, Any] | None
|
Optional Voice channel configuration (VoiceChannelConfig or dict) |
None
|
rcs_config
|
RCSChannelConfig | dict[str, Any] | None
|
Optional RCS channel tuning (RCSChannelConfig or dict). RCS
itself is enabled by setting |
None
|
whatsapp_config
|
WhatsAppChannelConfig | dict[str, Any] | None
|
Optional WhatsApp channel tuning (WhatsAppChannelConfig
or dict). WhatsApp itself is enabled by setting |
None
|
chat_config
|
ChatChannelConfig | dict[str, Any] | None
|
Optional Chat channel configuration (ChatChannelConfig or dict) |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
channels |
The full |
|
voice |
VoiceChannel instance for voice conversations |
|
sms |
SMSChannel instance for SMS conversations |
|
chat |
ChatChannel instance for web chat conversations |
|
rcs |
RCSChannel, or None when no RCS sender ID is configured |
|
whatsapp |
WhatsAppChannel, or None when no WhatsApp number is configured |
Example
from tac import TAC, TACConfig
from tac.server import TACFastAPIServer
from tac.models.session import ConversationSession
from tac_aws.connectors import StrandsConnector
from strands import Agent
from strands.session.file import FileSessionManager
tac = TAC(config=TACConfig.from_env())
# Agent factory with context for SessionManager
def create_agent(context: ConversationSession) -> Agent:
return Agent(
model="amazon.nova-pro-v1:0",
system_prompt="You are helpful.",
session_manager=FileSessionManager(
session_id=context.conversation_id,
base_path="./sessions"
)
)
# Create connector with agent factory. Every channel whose Twilio
# sender is configured is built for you — set TWILIO_WHATSAPP_NUMBER
# and connector.whatsapp comes along with SMS.
connector = StrandsConnector(tac=tac, agent_factory=create_agent)
# Use connector's channels for server
server = TACFastAPIServer(
tac=tac,
voice_channel=connector.voice,
messaging_channels=connector.channels.messaging,
)
server.start()
Initialize Strands connector with agent factory and channel configs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tac
|
TAC
|
TAC instance |
required |
agent_factory
|
Callable[[ConversationSession], Agent]
|
Factory function that creates a new Agent instance. Receives ConversationSession context as parameter. |
required |
sms_config
|
SMSChannelConfig | dict[str, Any] | None
|
Optional SMS channel configuration |
None
|
voice_config
|
VoiceChannelConfig | dict[str, Any] | None
|
Optional Voice channel configuration |
None
|
rcs_config
|
RCSChannelConfig | dict[str, Any] | None
|
Optional RCS channel tuning; TWILIO_RCS_SENDER_ID enables RCS |
None
|
whatsapp_config
|
WhatsAppChannelConfig | dict[str, Any] | None
|
Optional WhatsApp channel tuning; TWILIO_WHATSAPP_NUMBER enables WhatsApp |
None
|
chat_config
|
ChatChannelConfig | dict[str, Any] | None
|
Optional Chat channel configuration |
None
|
Channels¶
Every connector builds the same channel set — Voice, SMS, RCS, WhatsApp, and
Chat — and routes responses through it. connector.channels exposes it.
tac_aws.connectors.channels ¶
The channel set the AWS connectors build and route responses through.
Every connector in this package manages the same thing: one channel per Twilio
channel TAC supports, plus the routing that picks the right one for an inbound
message. That shared piece lives here so StrandsConnector, BedrockConnector,
and BedrockAgentCoreConnector differ only in how they reach their agent
runtime.
ChannelResponse
module-attribute
¶
ChannelResponse = str | AsyncGenerator[str, None]
A response to deliver: complete text, or a stream of tokens.
ConnectorChannels ¶
ConnectorChannels(tac: TAC, voice_config: VoiceChannelConfig | dict[str, Any] | None = None, sms_config: SMSChannelConfig | dict[str, Any] | None = None, rcs_config: RCSChannelConfig | dict[str, Any] | None = None, whatsapp_config: WhatsAppChannelConfig | dict[str, Any] | None = None, chat_config: ChatChannelConfig | dict[str, Any] | None = None)
The TAC channels a connector owns, and the routing between them.
Voice, SMS, and Chat are always created. RCS and WhatsApp are created only
when their Twilio sender is configured — TWILIO_RCS_SENDER_ID /
TACConfig.rcs_sender_id for RCS, TWILIO_WHATSAPP_NUMBER /
TACConfig.whatsapp_number for WhatsApp — because RCSChannel and
WhatsAppChannel raise ValueError at construction without one. The
*_config arguments are tuning only (memory_mode, dedup, agent identity);
they never enable or disable a channel.
Attributes:
| Name | Type | Description |
|---|---|---|
voice |
|
|
sms |
|
|
chat |
|
|
rcs |
|
|
whatsapp |
|
|
messaging |
list[MessagingChannel]
|
Every available messaging channel, ready to hand to a server as
|
Example
# With TWILIO_WHATSAPP_NUMBER set, connector.whatsapp is ready to use.
connector = StrandsConnector(
tac=tac,
agent_factory=create_agent,
sms_config=SMSChannelConfig(memory_mode="always"),
)
server = TACAWSFastAPIServer(
tac=tac,
voice_channel=connector.voice,
messaging_channels=connector.channels.messaging,
)
get ¶
get(channel_name: str) -> BaseChannel | None
The available channel with this TAC channel name, or None.
send
async
¶
send(context: ConversationSession, response: ChannelResponse, role: str = 'assistant') -> bool
Send a response on the channel the conversation arrived on.
A streamed response goes to the voice channel token by token; messaging channels send one complete message, so a stream is collected first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ConversationSession
|
Conversation session — |
required |
response
|
ChannelResponse
|
Complete text, or an async generator of tokens. |
required |
role
|
str
|
Message role passed through to the channel. |
'assistant'
|
Returns:
| Type | Description |
|---|---|
bool
|
True if a channel handled it; False when no channel is available for |
bool
|
|
AgentCore Runtime Configuration¶
Configuration objects for BedrockAgentCoreConnector.
tac_aws.connectors.bedrock_agentcore.config ¶
Configuration schemas for AgentCore connector.
WebSocketConfig ¶
Bases: BaseModel
WebSocket configuration for voice channel optimization.
RuntimeConfig ¶
Bases: BaseModel
Runtime configuration for AgentCore connector.
validate_websocket
classmethod
¶
validate_websocket(v: dict[str, Any] | WebSocketConfig | None) -> WebSocketConfig | None
Convert dict to WebSocketConfig if needed.