think() calls. This is useful when you need the agent to remember previous interactions within a conversation.
Creating a Session
Create a session usingagent.createSession():
Multi-Turn Conversations
Unlike standaloneagent.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 withSessionOptions:
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:
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
agent.think() calls when:
- Each request is independent
- You don’t need conversation history
- You want simpler, stateless interactions
