What you’ll build
A chat panel next to a lesson. The student types a question; the tutor streams a grounded answer; the student can keep going.1. Start a thread
A thread is the unit of conversation. You start one per(student, activity) pair:
thread.id somewhere keyed on (student, activity). Reuse it
across page loads.
2. Send a message
chunk object also carries citations — pointers into the lesson
content the tutor used. Render them as footnote-style links next to the
streamed text.
3. Read the history
When the student returns later, replay the thread:4. Wire the UI
Minimal React example:How tutor grounding works
The tutor’s context window is built from:- The parent
Course’sai.instructions(tone, voice, scope). - The
Lessoncontent + activities. - The student’s prior thread messages (truncated by token budget).
Auth: don’t ship your platform key
Use the token flow so the session key in the browser is scoped to one student:Cost & limits
- ~$0.02 per student-question on default settings.
- Threads have a soft cap of 50 messages; over that, the SDK summarises the oldest messages automatically.
- A
tutor.sendcall returns within 5–15 seconds for non-streaming and starts streaming within 1 second.