A Session is the unit of work in Qoder Cloud Agents. It pairs an Agent (configuration) with an Environment (infrastructure) to form a stateful conversation. You send messages to a Session and receive a stream of events back.Documentation Index
Fetch the complete documentation index at: https://docs.qoder.com/llms.txt
Use this file to discover all available pages before exploring further.
Session Lifecycle
A Session is a state machine. The core states are:
| State | Description | Transitions to |
|---|---|---|
idle | Idle, awaiting a user message | processing, cancelled |
processing | The Agent is executing | idle, cancelled |
cancelled | Cancelled and terminated | — (terminal) |
Field Reference
| Field | Type | Description |
|---|---|---|
id | string | System-generated, prefixed with ses_ |
agent_id | string | The bound Agent ID |
environment_id | string | The bound Environment ID |
status | string | Current state: idle / processing / cancelled |
title | string/null | Optional Session title |
metadata | object | Custom key-value pairs |
usage | object | Token usage stats |
usage.input_tokens | integer | Cumulative input tokens |
usage.output_tokens | integer | Cumulative output tokens |
created_at | string | Creation timestamp |
updated_at | string | Last update timestamp |
Create a Session
A Session needs bothagent and environment_id.
Option 1: Pass an Agent ID (string)
Binds the latest version of the Agent:Option 2: Pass an Agent Object (pin a version)
Binds a specific version of the Agent for behavioral consistency:In production, prefer Option 2 (pinned version) so Agent updates do not change Session behavior unexpectedly.
agent Field Format
| Format | Example | Behavior |
|---|---|---|
| String | "ag_r4nD0mId123" | Uses the latest version of the Agent |
| Object | {"id": "ag_r4nD0mId123", "version": 2} | Pins to the specified version |
State Transitions
Event request body format
POST /sessions/{id}/events requests must wrap events in an events array, and content is an array of content blocks:
| Field | Type | Required | Description |
|---|---|---|---|
events | array | Yes | Event array — one or more events per request |
events[].type | string | Yes | Event type, e.g. user.message |
events[].content | array | Yes | Content block array |
events[].content[].type | string | Yes | Content block type, e.g. text |
events[].content[].text | string | Yes | Text content |
idle → processing
Sending a user.message event moves the Session from idle to processing:
processing → idle
When the Agent finishes a turn the Session returns to idle. You will receive a session.status_idle event on the stream.
Cancel a Session
Force-terminate a running Session:Cancellation is terminal. A cancelled Session cannot be resumed; create a new Session instead.
Read Sessions
Usage Stats
Each Session tracks cumulative token usage:| Field | Description |
|---|---|
usage.input_tokens | Total input tokens across all requests |
usage.output_tokens | Total output tokens across all responses |
Session and Agent Version Binding
A Session snapshots its Agent configuration at creation time:- The string form
"agent": "ag_xxx"binds the latest version at creation time. - The object form
"agent": {"id": "ag_xxx", "version": N}pins to an exact version. - Once a Session exists, modifying the Agent does not change the Session.
- To use a new Agent version, create a new Session.
Session A — bound to Agent v1
Created before the update. Continues to use v1 even after the Agent has been updated to v2.
Session B — bound to Agent v2
Created after the update. Uses the new v2 configuration.
Multi-Turn Conversations
Sessions support multi-turn conversations. After each message, wait forsession.status_idle before sending the next:
Best Practices
- Pin versions — always create production Sessions with
{"id": ..., "version": ...}. - Cancel promptly — cancel Sessions you no longer need to free resources.
- Watch usage — review
usageperiodically to catch unexpected token spend. - Use metadata — record business context (task ID, trigger source) in
metadata.
FAQ
Q: Do Sessions time out? A: Sessions stayidle for a while; long-inactive Sessions may be archived automatically. Create Sessions on demand and cancel them when work completes.
Q: What happens if I send a message to a processing Session?
A: The request fails. Wait until the Session returns to idle before sending the next message.
Q: Is there a maximum number of turns per Session?
A: There is no hard limit on turns, but the model context window applies. Older content may be truncated as the conversation grows.
Q: How do I retrieve the full conversation history?
A: Use GET /sessions/{id}/events to fetch every event for the Session, including user messages and Agent responses.
Q: Can I resume a cancelled Session?
A: No — cancelled is terminal. Create a new Session and pass relevant context in the first message.
Next Steps
- Overview — review the Cloud Agents architecture.
- Quickstart — full end-to-end example.
- Defining an Agent — Agent configuration in depth.
- Cloud Environments — customize the runtime.