Google Cloud connectors
This guide shows you how to connect Google Cloud agents to Twilio communication channels using the twilio-agent-connect-google package. The package provides connectors that handle channel routing, memory context, and session management. This guide covers four connectors: ADK Agent Engine, Studio Agent Engine, CX Agent Studio, and Conversational Agents.
When you're ready to deploy to production, see Deploy to Google Cloud Run.
Before you begin, make sure you have:
- TAC SDK installed and configured with your Twilio credentials and a Conversation Configuration (see Add TAC to your agent prerequisites)
- A Google Cloud project with billing enabled
- Application Default Credentials configured locally (
gcloud auth application-default login) - Python 3.10 or later, within the range that the
twilio-agent-connect-googlepackage supports
The twilio-agent-connect-google package provides connectors for different Google Cloud agent services.
| Connector | Use case | Install extra |
|---|---|---|
ADKAgentEngineConnector | Use a Google Agent Development Kit (ADK) agent deployed on Agent Platform Runtime (Reasoning Engine). | vertex-ai |
StudioAgentEngineConnector | Use an Agent Studio app deployed on Agent Platform Runtime. The connector calls the streamQuery REST endpoint. | vertex-ai |
CXAgentStudioConnector | Use an agent built in CX Agent Studio (Customer Engagement Suite). Supports text and native speech-to-speech voice. | cx-agent-studio |
ConversationalAgentsConnector | Use an agent built in Conversational Agents (Dialogflow CX). Works with Playbook and Flow agents. | conversational-agents |
All connectors support voice and messaging. SMS, Voice, and Chat are always available. RCS and WhatsApp activate automatically when you set TWILIO_RCS_SENDER_ID or TWILIO_WHATSAPP_NUMBER alongside your TAC credentials.
The ADKAgentEngineConnector connects Twilio to an ADK agent deployed on Agent Platform Runtime. The connector creates one session per conversation and reuses it across turns, so ADK manages conversation history on the server.
pip install twilio-agent-connect-google[vertex-ai,server]
Add the following to your .env file alongside your existing TAC credentials.
1GOOGLE_CLOUD_PROJECT=your-project-id2GOOGLE_CLOUD_LOCATION=us-central13GCP_REASONING_ENGINE_ID=your-reasoning-engine-id
1import os23import vertexai4from dotenv import load_dotenv5from tac import TAC, TACConfig6from tac.channels.sms import SMSChannelConfig7from tac.channels.voice import VoiceChannelConfig8from tac.server import TACFastAPIServer910from tac_google.connectors import ADKAgentEngineConnector1112load_dotenv()1314GCP_PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"]15GCP_LOCATION = os.environ["GOOGLE_CLOUD_LOCATION"]16REASONING_ENGINE_ID = os.environ["GCP_REASONING_ENGINE_ID"]1718client = vertexai.Client(project=GCP_PROJECT, location=GCP_LOCATION)19tac = TAC(config=TACConfig.from_env())20agent = client.agent_engines.get(21name=f"projects/{GCP_PROJECT}/locations/{GCP_LOCATION}/reasoningEngines/{REASONING_ENGINE_ID}"22)2324connector = ADKAgentEngineConnector(25tac=tac,26agent=agent,27voice_config=VoiceChannelConfig(memory_mode="once"),28sms_config=SMSChannelConfig(memory_mode="once"),29)3031server = TACFastAPIServer(32tac=tac,33voice_channel=connector.voice,34messaging_channels=[connector.sms],35)3637if __name__ == "__main__":38server.start()
The connector automatically:
- Retrieves memory context from Conversation Memory and includes it in the first message (when
memory_modeis set to"always"or"once") - Routes responses to the correct channel
- Reuses one ADK session for the life of each conversation
To disable memory retrieval, omit voice_config and sms_config or set memory_mode to "never".
The StudioAgentEngineConnector connects Twilio to a source-code app that you build and deploy from the Agent Studio console. Agent Studio apps don't register SDK query or stream_query methods, so the connector calls the streamQuery REST endpoint instead. Session handling works the same way as the ADK connector.
pip install twilio-agent-connect-google[vertex-ai,server]
Add the following to your .env file alongside your existing TAC credentials.
1GOOGLE_CLOUD_PROJECT=your-project-id2GOOGLE_CLOUD_LOCATION=us-west13GCP_REASONING_ENGINE_ID=your-reasoning-engine-id
Info
Agent Studio currently stores and deploys agents in us-west1 only. Set GOOGLE_CLOUD_LOCATION to us-west1.
1import os23import vertexai4from dotenv import load_dotenv5from tac import TAC, TACConfig6from tac.channels.sms import SMSChannelConfig7from tac.channels.voice import VoiceChannelConfig8from tac.server import TACFastAPIServer910from tac_google.connectors import StudioAgentEngineConnector1112load_dotenv()1314GCP_PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"]15GCP_LOCATION = os.environ["GOOGLE_CLOUD_LOCATION"]16REASONING_ENGINE_ID = os.environ["GCP_REASONING_ENGINE_ID"]1718client = vertexai.Client(project=GCP_PROJECT, location=GCP_LOCATION)19tac = TAC(config=TACConfig.from_env())20agent = client.agent_engines.get(21name=f"projects/{GCP_PROJECT}/locations/{GCP_LOCATION}/reasoningEngines/{REASONING_ENGINE_ID}"22)2324connector = StudioAgentEngineConnector(25tac=tac,26agent=agent,27voice_config=VoiceChannelConfig(memory_mode="once"),28sms_config=SMSChannelConfig(memory_mode="once"),29)3031server = TACFastAPIServer(32tac=tac,33voice_channel=connector.voice,34messaging_channels=[connector.sms],35)3637if __name__ == "__main__":38server.start()
The connector uses the same memory and session behavior as the ADK connector.
The CXAgentStudioConnector connects Twilio to an agent built in the CX Agent Studio console (Customer Engagement Suite). Voice runs in one of two modes:
| Cascaded (default) | Speech-to-speech | |
|---|---|---|
| Call transport | ConversationRelay, text over a WebSocket | Media Streams, raw audio over a WebSocket |
| Speech-to-text and text-to-speech | Twilio | CX Agent Studio |
| Agent API | runSession (text) | BidiRunSession (audio) |
| Conversation Orchestrator and Conversation Memory | Supported | Not supported for voice |
Messaging channels (SMS, RCS, WhatsApp, and Chat) always use the text runSession API with Conversation Orchestrator and Conversation Memory.
pip install twilio-agent-connect-google[cx-agent-studio,server]
Add the following to your .env file alongside your existing TAC credentials.
CX_AGENT_ID=projects/your-project/locations/your-location/apps/your-app-id
The service account or user running the server needs the roles/ces.client role on the agent.
1import os23from dotenv import load_dotenv4from tac import TAC, TACConfig5from tac.channels.sms import SMSChannelConfig6from tac.channels.voice import VoiceChannelConfig78from tac_google.connectors import CXAgentStudioConnector9from tac_google.connectors.cx_agent_studio.server import CXAgentStudioFastAPIServer1011load_dotenv()1213CX_AGENT_ID = os.environ["CX_AGENT_ID"]1415tac = TAC(config=TACConfig.from_env())1617connector = CXAgentStudioConnector(18tac=tac,19agent_id=CX_AGENT_ID,20voice_config=VoiceChannelConfig(memory_mode="once"),21sms_config=SMSChannelConfig(memory_mode="once"),22)2324server = CXAgentStudioFastAPIServer(25tac=tac,26voice_channel=connector.voice,27messaging_channels=[connector.sms],28)2930if __name__ == "__main__":31server.start()
To use native speech-to-speech voice, see the getting_started/examples/cx_agent_studio/s2s.py example in the repository.
The ConversationalAgentsConnector connects Twilio to an agent built in the Conversational Agents (Dialogflow CX) console. The connector calls the Dialogflow CX detectIntent API. Twilio ConversationRelay handles speech, so the connector exchanges text only, and Dialogflow keeps conversation history on the server for each session ID.
pip install twilio-agent-connect-google[conversational-agents,server]
Add the following to your .env file alongside your existing TAC credentials.
1CONVERSATIONAL_AGENT_ID=projects/your-project/locations/us-central1/agents/your-agent-id2DIALOGFLOW_LANGUAGE_CODE=en
The service account or user running the server needs the roles/dialogflow.client role.
1import os23from dotenv import load_dotenv4from tac import TAC, TACConfig5from tac.channels.sms import SMSChannelConfig6from tac.channels.voice import VoiceChannelConfig7from tac.server import TACFastAPIServer89from tac_google.connectors import ConversationalAgentsConnector1011load_dotenv()1213CONVERSATIONAL_AGENT_ID = os.environ["CONVERSATIONAL_AGENT_ID"]14DIALOGFLOW_LANGUAGE_CODE = os.environ.get("DIALOGFLOW_LANGUAGE_CODE", "en")1516tac = TAC(config=TACConfig.from_env())1718connector = ConversationalAgentsConnector(19tac=tac,20agent_id=CONVERSATIONAL_AGENT_ID,21language_code=DIALOGFLOW_LANGUAGE_CODE,22voice_config=VoiceChannelConfig(memory_mode="once"),23sms_config=SMSChannelConfig(memory_mode="once"),24)2526server = TACFastAPIServer(27tac=tac,28voice_channel=connector.voice,29messaging_channels=[connector.sms],30)3132if __name__ == "__main__":33server.start()
To start from a working example instead of writing the server code yourself, clone the twilio-agent-connect-google repository and run one of the included examples.
-
Clone the repository and install dependencies:
1git clone https://github.com/twilio/twilio-agent-connect-google.git2cd twilio-agent-connect-google3make sync4make dev-setup -
Create a
.envfile in the examples directory:cp getting_started/examples/.env.example getting_started/examples/.env -
Fill in your TAC credentials and the Google Cloud variables for the connector you want to run:
ADK Agent EngineStudio Agent EngineCX Agent StudioConversational Agents1GOOGLE_CLOUD_PROJECT=your-project-id2GOOGLE_CLOUD_LOCATION=us-central13GCP_REASONING_ENGINE_ID=your-reasoning-engine-id -
From the repository root, start the example server:
ADK Agent EngineStudio Agent EngineCX Agent StudioConversational Agentsuv run getting_started/examples/agent_platform/adk_agent_engine.py -
Expose your local server with ngrok so Twilio can reach it, then configure your Twilio webhooks to point at the ngrok domain. For detailed steps, see Expose your local server with ngrok and Configure Twilio webhooks.
The repository also includes examples that enable a single messaging channel (features/whatsapp.py, features/rcs.py) and a browser-based web chat (features/chat/) that runs entirely on localhost.
- Start your server and make sure ngrok is running.
- Send an SMS to your Twilio phone number and verify that you receive a response.
- Call your Twilio phone number and verify that the voice channel works.
- If you configured Conversation Memory, verify that responses include personalized context from the customer's profile.
- Deploy to Google Cloud Run: Deploy your TAC application to production on Google Cloud.
- Add TAC to your agent: Add custom tools and knowledge search.
- Troubleshooting: Common issues and solutions.