Create and reuse

A session is the runtime context for an agentic run: the scoped environment an AI agent works in while it acts for one of your users. You create it with composio.create(userId), and it ties together the user, the toolkits available, authentication, and connected accounts. By default it gives the agent meta tools to discover, authenticate, and execute app tools at runtime, instead of loading hundreds of tool definitions into context.

What comes in a session

By default, a session gives your agent meta tools to discover and execute app tools and manage connections for your user. All toolkits are discoverable, and search includes skill guidance when a matching skill exists. Standard sessions also include a sandbox for processing files and large responses outside the model's context window. You can restrict tool access or disable the sandbox through session configuration.

Use tool access rules, tool loading, connection selection, and sandbox options to configure a session for your task.

Users

A user is an identifier from your app. Composio stores connections under that ID, so tools run with the right account and stay isolated from other users. Use a stable identifier like your database ID, never one that can change.

A user can connect multiple accounts for the same toolkit, like work and personal Gmail. Use the same userID, then select the connected account when a session needs a specific one. See Managing multiple connected accounts.

Creating a session

session = composio.sessions.create(user_id="user_123")

By default, a session has access to every toolkit in the Composio catalog. Your agent can discover and use any of them through COMPOSIO_SEARCH_TOOLS. Use the options below to restrict or customize what's available.

You can also attach local tools and local toolkits that run in-process alongside Composio tools. See Local tools and toolkits.

Both SDKs pass product and runtime identity through the API client's identity option. If you configure custom default or request headers, remove identity headers such as x-source, x-framework, x-sdk-version, and x-client-*. The client rejects attempts to override them.

API key permissions

If you use a scoped project API key, grant permissions for the session operations your application needs:

  • Session management controls creating, viewing, configuring, and deleting sessions. It does not grant tool execution access.
  • Session tool execution covers search, tool execution, proxy execution, and session-linked MCP access.

Enable both permissions if your application manages sessions and executes tools through them.

The basics

Create a session for a user, then read its tools formatted for your framework. To connect over MCP instead, see Using sessions via MCP.

session = composio.sessions.create(user_id="user_123")

tools = session.tools()

A session scopes four things:

  • userID: whose connected accounts and tool executions are in scope.
  • Tool access: all toolkits by default, or a filtered set of toolkits, tools, or tags.
  • Authentication: managed auth, custom auth configs, and connected-account selection.
  • Execution state: logs, tool memory, MCP state, and workbench files for the task.

How sessions behave

Every create() call returns a new session ID. Use it for a fresh task context.

Sessions persist on the server and don't expire. For multi-turn conversations, store the session ID and reuse it with composio.use() instead of calling create() again.

session = composio.use("session_id")
tools = session.tools()

You can also update a session in place instead of creating a new one:

session.update(
    toolkits={"enable": ["gmail", "slack"]},
    auth_configs={"gmail": "ac_new_config"},
    connected_accounts={"slack": ["ca_work_slack"]},
)

Create a new session for a different user or a fundamentally different task setup. Reuse or update a session when the same conversation should keep its tool, auth, and workbench context.

delete()

Delete a session when you're done with it. Deleted sessions immediately stop being retrievable or executable, and the call returns the deleted session_id. Deleting a missing or already-deleted session surfaces the backend 404.

Requires @composio/core ≥ 0.13.1 (TypeScript) or composio ≥ 0.17.1 (Python).

result = session.delete()
print(result["session_id"], result["deleted"])

For framework examples, see OpenAI or Vercel AI SDK. To connect over MCP, see Using sessions via MCP.