Skip to content
Docs menu

Sessions and tool scope

Give each user or client its own tools, switch sessions with update_session_id, and what the client:session identifier is.

Your tools belong to a session. Build the client once and the session exists; every later call uses it. This page shows how to use one session, how to give each user or client their own, and what happens underneath.

One session, no work

catalyst = Catalyst()               # a private session is created: sdk-<random>
print(catalyst.session_id)
catalyst.tools.register([place_clip])

Everything you do next maps to that session: generating, downloading, chatting, registering and listing tools. You do not pass a session id again.

A session per user or per client

Switch the client's session with **update_session_id**. It checks the id, makes it the default for every later call, and returns it.

catalyst.update_session_id("customer-42")       # the session every later call uses
catalyst.tools.register([place_clip, add_marker])

catalyst.update_session_id("customer-43")       # another customer: a separate set of tools
print([t.name for t in catalyst.tools.list()])  # nothing yet

catalyst.update_sessionId("customer-42")        # the same method, camelCase spelling

Output from the local mock server (a real run of the Python SDK):

Output
customer-42: ['add_marker', 'place_clip']
customer-43: []
customer-43: ['place_clip']

The third line is after registering place_clip in customer-43. Each session has its own tools; they never mix.

Rules for a session id

The same rules as every session id: letters, digits, ., _, : and -; it starts with a letter or digit; up to 160 characters. The id you choose is yours. Using it again continues that session, even weeks later. A bad id is refused before anything is sent:

Output
InvalidRequestError: 422 INVALID_REQUEST session_id: must start with a letter or digit and use only letters, digits, '.', '_', ':' and '-' (max 160 characters).

One client, many sessions

If one Catalyst object serves many users (a web server), do not share it across requests while switching its session. Give each request its own object, or pass the session explicitly on each call:

catalyst.tools.register([place_clip], session_id="customer-42")
catalyst.tools.list(session_id="customer-42")
catalyst.chat.create("add a whoosh", session_id="customer-42", tools=True)
Note

Tools belong to the session they were registered in. After update_session_id, register the tools again if the new session should have them. Registration is cheap and safe to repeat.

Named tool sets: client_id

Inside one session you can keep more than one set of tools, for example one per application. The set's name is client_id; the default is sdk.

catalyst.tools.register([place_clip], client_id="premiere")
catalyst.tools.register([add_marker], client_id="resolve")
catalyst.chat.create("add a whoosh", client_id="premiere")      # the agent sees only the premiere tools

catalyst.client_id = "premiere"                                  # change the default name
catalyst = Catalyst(client_id="premiere")                        # or set it when you build the client

What is sent: client_id:session_id

The API stores a tool set under your account and one identifier, client_id. It has no separate idea of a session for tools. To keep each session's tools apart, the SDK builds that identifier from both:

Output
client_id on the wire  =  <your client_id> + ":" + <session_id>

For the default client sdk and the session customer-42 the identifier is sdk:customer-42. You can see it:

catalyst.tools.scope_id()                                          # sdk:customer-43
catalyst.tools.scope_id(client_id="premiere", session_id="project-9")   # premiere:project-9
Output
scope: sdk:customer-43
explicit: premiere:project-9

Why it is built this way

  • No server change. The identifier is a name the API already accepts (letters, digits, ., _, :, -, up to 160 characters), so session-scoped tools work today with nothing new on the server.
  • One rule everywhere. Registering, listing, deleting and chatting all build the identifier the same way, so a tool registered in a session is found by a chat in the same session and by nothing else.
  • You rarely see it. It appears in tools.list() results (client_id) and when you call the HTTP API yourself. With cURL you write it yourself: "client_id": "sdk:customer-42".
  • The length limit is on the whole thing. client_id plus : plus the session id must fit in 160 characters. The SDK checks it before sending.

If you call the HTTP API directly (cURL, another language), use the same convention and your tools line up with the SDKs'. If you would rather not scope by session, register with the plain name ("client_id": "premiere") and chat with the same name: that works too, and it is what the older register(client_id, tools) call does.