Update a session

Reading and updating session configuration

In TypeScript, session.config exposes the configuration returned by the server. Call session.update() to change selected fields. It preserves omitted fields, updates session.config in place, and returns the updated configuration. See Updating a session for an example.

ToolRouterSessionConfig and ToolRouterSessionConfigHistoryConfig use the API client's types. The SDK returns the config as sent by the API, without validating instant at runtime or removing premium_usage. instant is always present as false or a policy object. Use ToolRouterSessionConfig['instant'] when you need its TypeScript type.

When inspecting a returned config, handle toolkits and individual tools entries that contain only require_approval, without enabled or disabled. tags can also carry require_approval, and the config can include proxy_execute. These fields also appear in configurations returned by session.listConfigHistory().

In Python, session.config.instant is a model when it contains a policy. Read its fields with attribute access rather than dictionary indexing, just as you do for Instant charges.

If you implement the TypeScript Session interface yourself, include the required config member. Sessions created by the SDK provide it automatically.

Updating a session

session.update() patches the stored configuration in place. Fields you omit are preserved, so you can widen or narrow one part of a session without restating the rest. The SDK refreshes session.config and the session's config version only after the API accepts the change.

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

session.update(toolkits={"enable": ["gmail", "github"]})

The update behavior below requires @composio/core ≥ 0.19.1 (TypeScript) or composio ≥ 0.22.1 (Python).

Maps replace, they don't merge

A tools, authConfigs, or connectedAccounts map you send replaces the stored map entirely. The API does not merge entries, so a Slack-only tools map removes a Gmail entry that was stored before it.

Stored before the update:

{
  "tools": {
    "gmail": { "enable": ["GMAIL_FETCH_EMAILS"] },
    "slack": { "enable": ["SLACK_SEND_MESSAGE"] }
  }
}

The update:

session.update(
    tools={"slack": {"enable": ["SLACK_SEND_MESSAGE", "SLACK_LIST_CHANNELS"]}},
)

Stored after the update. The gmail entry is gone:

{
  "tools": {
    "slack": { "enable": ["SLACK_SEND_MESSAGE", "SLACK_LIST_CHANNELS"] }
  }
}

To change one entry, send the whole map with every entry you want to keep. An empty map ({}) is stored as an explicit empty map.

The same rule applies to toolkits, tags, and preload: a value replaces the stored policy. manageConnections, sandbox, and multiAccount merge the subfields you send, and an empty object changes nothing.

Narrowing an existing session to no app toolkits

An empty allowlist on update denies every app toolkit, exactly as it does on create. The SDK sends { "enable": [] } as-is instead of dropping it from the request.

session.update(toolkits={"enable": []})

Removing a callback URL

manageConnections.callbackUrl: null removes only the stored callback URL. enable and the other connection settings stay as they are. An empty string is rejected.

session.update(manage_connections={"callback_url": None})

Clearing a block with null

Passing null (None in Python) for a whole block removes the stored override and the session falls back to the default for that block. Every policy block accepts it: toolkits, tools, tags, authConfigs, connectedAccounts, preload, manageConnections, sandbox, proxyExecute, multiAccount, search, execute, and experimental.

session.update(manage_connections=None, multi_account=None)

Clearing a policy can widen access. toolkits: null removes the toolkit policy and restores the unrestricted default, which is the opposite of { "enable": [] }; clearing preload does the same for preloaded tools, so the agent can reach more than before the update. Send toolkits: [] when you want to deny every app toolkit. Clearing multiAccount resolves to disabled, while omitting it preserves the stored setting.

Blocks you can set only on update

search, execute, and experimental are not part of create(). Reach them with session.update() on an existing session.

session.update(
    search={"enable": False},
    execute={"enable_multi_execute": False},
)

Both blocks are on by default. search controls the session's search helper, so disabling it leaves the agent with the tools you preloaded. execute.enableMultiExecute controls whether the agent can run several tool calls in one request. manageConnections.enableConnectionRemoval is update-only as well, and controls whether the session exposes the connection-removal tool.

The experimental block on update holds server-side session settings: permissions, linkUrlOverwrite, fastMode, submitFeedback, and sessionConfigId. sessionConfigId applies a saved Session config and can't be combined with toolkits, tools, or tags. The experimental block on update is a different field from the experimental option on create(), which holds local tools and toolkits that run in your process, so experimental: null on an update leaves those alone.

Multi-account mode after an update

The canonical disabled state is { "enable": false, "require_explicit_selection": false } with no maximum. Sending enable: false resets a stale maximum or selection setting, and reapplying that disabled configuration is accepted. Combining enable: false with maxAccountsPerToolkit or requireExplicitSelection: true is rejected with a 400.

Preload must stay inside the policy

An update that narrows toolkits, tools, or tags while leaving an explicitly preloaded tool outside the new policy is rejected with a 400, and nothing changes. Fix preload in the same update:

session.update(
    toolkits={"enable": ["slack"]},
    preload={"tools": ["SLACK_SEND_MESSAGE"]},
)

Concurrent updates

Every session response carries a config version (session.configVersion in TypeScript, session.config_version in Python, config_version on the wire). By default, session.update() sends no precondition, so the last writer wins. To make an update conditional, pass the version you read as expectedConfigVersion (expected_config_version in Python). The API then applies the update only when the stored version still matches. Otherwise it answers 409 and writes nothing: no config change, no history entry, no cache update. The SDK never retries that request, so a conflict is reported exactly once.

The API must support expected_config_version. If it doesn't, it rejects a conditional update with a 400.

On a conflict, the SDK raises ComposioSessionConfigConflictError (TypeScript) or SessionConfigConflictError (Python) and leaves the session object as it was. Re-read the session with sessions.use(), reapply your change on top of the fresh config, and retry:

from composio.exceptions import SessionConfigConflictError

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

try:
    session.update(
        toolkits={"enable": ["gmail", "github"]},
        expected_config_version=session.config_version,
    )
except SessionConfigConflictError:
    # Another client changed the session first. Nothing was written.
    session = composio.sessions.use("session_id")
    session.update(
        toolkits={"enable": ["gmail", "github"]},
        expected_config_version=session.config_version,
    )

You can also pass a version you read elsewhere, for example one stored with a queued job. expectedConfigVersion: false (expected_config_version=False) is the same as omitting it. The API still commits only a fully validated configuration, so a losing update never leaves a half-applied session behind.

Raw HTTP callers set expected_config_version in the PATCH body themselves; without it the last writer wins.

To roll a session back, read a previous configuration from its config history (GET /api/v3.1/tool_router/session/{session_id}/config_history) and convert it into an update request. A history entry is not a request body: it carries metadata and version fields, and it names toolkits and tools as enabled and disabled, which map to enable and disable in the update.

update()

Patch the session configuration in place. See Updating a session for what omitted fields, replaced maps, null, and expectedConfigVersion do.

config = session.update(toolkits={"enable": ["gmail", "github"]})

Configuration history

Inspect the configurations a session has used with session.list_config_history(limit=10) in Python or await session.listConfigHistory({ limit: 10 }) in TypeScript. Results are newest first, with the live configuration first. Each session.update() archives the previous configuration.

The response contains items with each version's config and an is_current (Python) or isCurrent (TypeScript) flag. Pass the response's next_cursor (Python) or nextCursor (TypeScript) as cursor to fetch another page; limit supports up to 100 items per page.

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