Skip to main content
Sessions enable multi-turn conversations with an agent, maintaining context across multiple think() calls. This is useful when you need the agent to remember previous interactions within a conversation.

Creating a Session

Create a session using agent.createSession():

Multi-Turn Conversations

Unlike standalone agent.think() calls, prompts sent through a session maintain conversation context. The agent remembers what was discussed in previous turns:

Session Options

When creating a session, you can configure it with SessionOptions:

Session API

sessionId

The unique identifier for this session:

think(schema)

Create a Plan for constructing a prompt. Works the same as agent.think(), but maintains conversation context within the session:

close()

Close the session when you’re done. After closing, no more prompts can be sent through this session:
The agent connection remains open and can be used for other sessions or standalone calls.

Complete Example

Here’s a complete example showing a multi-turn code review session:

Sessions vs Standalone Calls

Use sessions when:
  • You need multi-turn conversations
  • Context from previous interactions matters
  • You’re building a conversational workflow
Use standalone agent.think() calls when:
  • Each request is independent
  • You don’t need conversation history
  • You want simpler, stateless interactions