Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

1.2 KB
Raw Blame
"""
Tool Router - Session Update Example

Demonstrates using session.update() to modify a session's configuration
after creation — e.g. adding toolkits, changing workbench settings, or
updating preload config without creating a new session.
"""

import os

from composio import Composio

composio = Composio()

# Create a session with gmail only
session = composio.create(
    # The provisioned examples user (raises KeyError when unset)
    user_id=os.environ["COMPOSIO_EXAMPLES_USER_ID"],
    toolkits=["gmail"],
    manage_connections=False,
)

print(f"Session created: {session.session_id}")
print(f"Preload: {session.preload}")

# Update: add github toolkit, enable workbench, and preload a tool
session.update(
    toolkits={"enable": ["gmail", "github"]},
    workbench={"enable": True, "sandbox_size": "medium"},
    preload={"tools": ["GITHUB_CREATE_AN_ISSUE"]},
)

print("\nAfter update:")
print(f"Preload: {session.preload}")

# Update: disable workbench entirely
session.update(
    workbench={"enable": False},
)

print("\nAfter disabling workbench: done")

# Update: clear manage_connections by passing None
session.update(
    manage_connections=None,
)

print("\nAfter clearing manage_connections: done")