|
| 1 | +--- |
| 2 | +catalog_title: ADK Connector |
| 3 | +catalog_description: Expose ADK agents as chatbots on popular messaging channels with cross-device session sync |
| 4 | +catalog_icon: /integrations/assets/adk-connector.png |
| 5 | +catalog_tags: ["connectors"] |
| 6 | +--- |
| 7 | + |
| 8 | +# ADK Connector |
| 9 | + |
| 10 | +<div class="language-support-tag"> |
| 11 | + <span class="lst-supported">Supported in ADK</span><span class="lst-python">Python</span><span class="lst-typescript">TypeScript</span> |
| 12 | +</div> |
| 13 | + |
| 14 | +[ADK Connector](https://github.com/Harshk133/adk-connector) is a plug-and-play |
| 15 | +toolkit that wraps any ADK agent and exposes it as a chatbot on popular |
| 16 | +messaging channels such as Telegram and Discord. See the project repository for |
| 17 | +the current list of supported channels. |
| 18 | + |
| 19 | +By adding just a few lines of code, you can bridge the gap between local |
| 20 | +development, testing, and production messaging platforms, with native support |
| 21 | +for database-backed cross-device session synchronization. |
| 22 | + |
| 23 | +## Use cases |
| 24 | + |
| 25 | +- **Multi-Channel Deployment**: Instantly deploy your ADK agents (written in |
| 26 | + Python or JavaScript/TypeScript) as chatbots on supported messaging channels |
| 27 | + like Telegram and Discord. |
| 28 | +- **Cross-Device Session Synchronization**: Seamlessly transition conversations. |
| 29 | + Chat on Telegram or Discord, then inspect, debug, and continue the exact same |
| 30 | + conversation inside the local ADK Web UI (`adk web`). |
| 31 | +- **Resilient State Management**: Automatically configures an asynchronous |
| 32 | + SQLite backend to record session states, tool invocations, and user |
| 33 | + interactions. |
| 34 | +- **Robust Multi-Agent Workflows**: Double-import safety and automatic |
| 35 | + resolution of prompt context variables across parent and sub-agents. |
| 36 | + |
| 37 | +## Prerequisites |
| 38 | + |
| 39 | +- Python 3.10+ or Node.js 18+ |
| 40 | +- A Gemini API Key (set as `GOOGLE_API_KEY`) |
| 41 | +- Messaging channel credentials: |
| 42 | + - **Telegram**: A Telegram account and a Bot Token from BotFather |
| 43 | + - **Discord**: A Discord developer account, a Discord Bot Token, and client ID |
| 44 | + |
| 45 | +## Installation |
| 46 | + |
| 47 | +You can install the connectors for either Python or JavaScript / TypeScript |
| 48 | +depending on your ADK project. |
| 49 | + |
| 50 | +=== "Python" |
| 51 | + |
| 52 | + ```bash |
| 53 | + pip install adk-connector |
| 54 | + ``` |
| 55 | + |
| 56 | + To enable database-backed cross-device session synchronization (e.g. `adk |
| 57 | + web` UI), also install the ADK DB components: |
| 58 | + |
| 59 | + ```bash |
| 60 | + pip install "google-adk[db]" |
| 61 | + ``` |
| 62 | + |
| 63 | +=== "JavaScript / TypeScript" |
| 64 | + |
| 65 | + ```bash |
| 66 | + npm install adk-connector-js |
| 67 | + ``` |
| 68 | + |
| 69 | +## Use with agent |
| 70 | + |
| 71 | +Here is how you can wrap your existing Google ADK agents and launch them on |
| 72 | +messaging channels. |
| 73 | + |
| 74 | +=== "Python (Telegram)" |
| 75 | + |
| 76 | + ```python |
| 77 | + import os |
| 78 | + from dotenv import load_dotenv |
| 79 | + from google.adk.agents.llm_agent import Agent |
| 80 | + from adk_connectors.telegram import TelegramConnector |
| 81 | + |
| 82 | + # Load environment variables |
| 83 | + load_dotenv() |
| 84 | + |
| 85 | + # 1. Define your standard Google ADK Agent |
| 86 | + assistant = Agent( |
| 87 | + model='gemini-flash-latest', |
| 88 | + name='my_assistant', |
| 89 | + instruction='You are a helpful assistant.' |
| 90 | + ) |
| 91 | + |
| 92 | + if __name__ == "__main__": |
| 93 | + # 2. Retrieve your Telegram Bot Token |
| 94 | + token = os.getenv("TELEGRAM_BOT_TOKEN") |
| 95 | + |
| 96 | + # 3. Bind the connector |
| 97 | + connector = TelegramConnector( |
| 98 | + token=token, |
| 99 | + agent=assistant |
| 100 | + ) |
| 101 | + |
| 102 | + # 4. Start polling |
| 103 | + connector.start() |
| 104 | + ``` |
| 105 | + |
| 106 | +=== "Python (Discord)" |
| 107 | + |
| 108 | + ```python |
| 109 | + import os |
| 110 | + from dotenv import load_dotenv |
| 111 | + from google.adk.agents.llm_agent import Agent |
| 112 | + from adk_connectors.discord import DiscordConnector |
| 113 | + |
| 114 | + # Load environment variables |
| 115 | + load_dotenv() |
| 116 | + |
| 117 | + # 1. Define your standard Google ADK Agent |
| 118 | + assistant = Agent( |
| 119 | + model='gemini-flash-latest', |
| 120 | + name='my_assistant', |
| 121 | + instruction='You are a helpful assistant.' |
| 122 | + ) |
| 123 | + |
| 124 | + if __name__ == "__main__": |
| 125 | + # 2. Retrieve your Discord Bot Token |
| 126 | + token = os.getenv("DISCORD_BOT_TOKEN") |
| 127 | + |
| 128 | + # 3. Bind the connector |
| 129 | + connector = DiscordConnector( |
| 130 | + token=token, |
| 131 | + agent=assistant |
| 132 | + ) |
| 133 | + |
| 134 | + # 4. Start the bot! |
| 135 | + connector.start() |
| 136 | + ``` |
| 137 | + |
| 138 | +=== "JavaScript / TypeScript (Telegram)" |
| 139 | + |
| 140 | + ```typescript |
| 141 | + import { LlmAgent } from '@google/adk'; |
| 142 | + import { TelegramConnector } from 'adk-connector-js'; |
| 143 | + import dotenv from 'dotenv'; |
| 144 | + |
| 145 | + dotenv.config(); |
| 146 | + |
| 147 | + // 1. Define your standard Google ADK Agent |
| 148 | + export const rootAgent = new LlmAgent({ |
| 149 | + name: 'my_assistant', |
| 150 | + model: 'gemini-flash-latest', |
| 151 | + instruction: 'You are a helpful assistant.' |
| 152 | + }); |
| 153 | + |
| 154 | + // 2. Launch the Telegram Connector under script entrypoint |
| 155 | + if (import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith('agent.ts')) { |
| 156 | + const connector = new TelegramConnector({ |
| 157 | + token: process.env.TELEGRAM_BOT_TOKEN!, |
| 158 | + agent: rootAgent |
| 159 | + }); |
| 160 | + |
| 161 | + connector.start(); |
| 162 | + } |
| 163 | + ``` |
| 164 | + |
| 165 | +## Session sync with `adk web` |
| 166 | + |
| 167 | +For Python setups, you can sync Telegram or Discord chat history directly with |
| 168 | +the local ADK Web UI by mapping your provider-specific user ID to the local |
| 169 | +development environment. |
| 170 | + |
| 171 | +1. In your code, set `session_management_across_device=True` and pass your user ID: |
| 172 | + |
| 173 | + === "Telegram" |
| 174 | + |
| 175 | + ```python |
| 176 | + connector = TelegramConnector( |
| 177 | + token=token, |
| 178 | + agent=assistant, |
| 179 | + session_management_across_device=True, # Spin up DB & mapping persistence |
| 180 | + dev_user_id=os.getenv("TELEGRAM_USER_ID") # Syncs this ID to the "user" Web UI namespace |
| 181 | + ) |
| 182 | + ``` |
| 183 | + |
| 184 | + === "Discord" |
| 185 | + |
| 186 | + ```python |
| 187 | + connector = DiscordConnector( |
| 188 | + token=token, |
| 189 | + agent=assistant, |
| 190 | + session_management_across_device=True, # Spin up DB & mapping persistence |
| 191 | + dev_user_id=os.getenv("DISCORD_USER_ID") # Syncs this ID to the "user" Web UI namespace |
| 192 | + ) |
| 193 | + ``` |
| 194 | + |
| 195 | +2. Run your bot script: |
| 196 | + ```bash |
| 197 | + python agent.py |
| 198 | + ``` |
| 199 | +3. Run the ADK Web UI in a separate terminal: |
| 200 | + ```bash |
| 201 | + adk web . |
| 202 | + ``` |
| 203 | +4. Access `http://127.0.0.1:8000` to view active conversations and tool |
| 204 | + execution logs directly in the browser. |
| 205 | + |
| 206 | +## Additional resources |
| 207 | + |
| 208 | +- [ADK Connector GitHub Repository](https://github.com/Harshk133/adk-connector) |
| 209 | +- [ADK Connector Python Package (PyPI)](https://pypi.org/project/adk-connector/) |
| 210 | +- [ADK Connector JS/TS Package (NPM)](https://www.npmjs.com/package/adk-connector-js) |
0 commit comments