Chat Sessions
Chat sessions let a deployed App continue a conversation across multiple messages.
When you call app.chat(message), the SDK stores the returned session_id and sends it with the next message automatically. You do not need to manage the session ID for normal multi-turn chat.
Send a Message
response = app.chat("My name is Alex.")
print(response.response)
print(response.session_id)
app.chat() returns a ChatResponse.
| Field | Description |
|---|---|
response | The assistant's reply. |
session_id | The session identifier returned by the API. |
retrieved_contexts | Data source chunks used for the response, if any. |
messages | Conversation messages returned by the API. |
raw_payload | The raw API response payload. |
Continue a Conversation
Call app.chat() again on the same App instance:
app.chat("My name is Alex.")
response = app.chat("What is my name?")
print(response.response)
The SDK sends the latest session ID automatically, so the assistant can use previous conversation context.
Check the Current Session ID
Use app.session_id to inspect the active session:
print(app.session_id)
Before the first message, this value is None. After a successful chat response, it contains the current session ID.
Reset the Session
Use reset_session() to start a fresh conversation:
app.chat("My name is Alex.")
app.reset_session()
response = app.chat("What is my name?")
print(response.response)
After resetting, the next message starts a new session instead of continuing the previous one.
Use the ChatSession Helper
You can also create a small session helper:
session = app.session()
response = session.ask("Summarize the uploaded handbook.")
print(response.response)
This helper uses the same underlying App session behavior.
Interactive Chat Mode
Call .chat() without a message to start an interactive terminal chat:
app.chat()
Type exit or quit to end the session.
Notes
- Session state is retained on the
Appinstance. - If you create a new
Appinstance, it starts without a retained session ID. - Use
reset_session()when you want a clean conversation. - Use
retrieved_contextsto inspect which knowledge chunks were used in responses from data sources.
Next Steps
- Data Sources and RAG: understand retrieved context.
- Error Handling: handle authentication, validation, and server errors.