Sessions
Session Overview
Understand the central role of Session in the Agent SDK and the most common usage sequence
Session Overview
In the SDK, the thing that actually executes work is the session.
Preferred local interactive pattern
Local Agent
const session = await agent.session();
await session.set({ model });
const turn = await session.prompt({ query: "Continue" });
const unsubscribe = session.subscribe((event) => {
console.log(event);
});
await turn.finished;RemoteAgent
const session = await remoteAgent.session();
const turn = await session.prompt({ query: "Continue" });
await turn.finished;Methods you will use most often
setpromptsubscribehistorysystemfork
If you remember only one thing, remember this: the real working object in the SDK is not Agent itself, but the session.
One important difference
- local sessions need
set({ model })first - remote sessions cannot currently receive a model instance from the client
So the biggest difference between local and remote usage is not the interaction shape. It is where the model is held and configured.
Usage guidance
- Use
prompt()to append new user input - Use
subscribe()to observe future turn events - Use
turn.finishedwhen you need the final result of a specific turn