Set up the project
Use Python 3.12 or Node.js 24.17 or newer. Install the packages in a new project, with a virtual environment for Python:- Python
- TypeScript
work-gmail and personal-gmail must be unique for that user and toolkit. In an application, derive the user ID from your authenticated user.
Connect both accounts and run the agent
On the first run, the script prints a Connect Link and waits for you to authorize each account. Open the work link in your work Google account and the personal link in your personal account. Check the account shown on Google’s consent screen before approving.- Python
- TypeScript
Save as
accounts.py:accounts.py
work-gmail or that account’s ID.
Reuse the connections
SetCOMPOSIO_SESSION_ID to the ID printed by the completed setup and rerun the script:
personal-gmail to check the other account. Keep the same COMPOSIO_USER_ID; an application must only restore session IDs belonging to its authenticated user.
If setup stops after connecting one account, use connected account management to inspect the connection before starting again. Re-running setup with the same aliases can conflict with existing connections.
Account selection and isolation
requireExplicitSelection requires an account argument when multiple active accounts are available. It prevents silent fallback to the default account. Both accounts are still accessible to this agent; the prompt is not an access-control boundary.
For an agent that must only access work Gmail, pin its session to the work connected account ID. For alias updates, connection limits, and account listings, see the multi-account guide.