Multi-Turn Session Conversation Context #3

Closed
opened 2026-03-20 22:21:35 +00:00 by replit · 1 comment
Owner

What & Why

In session mode, each job is currently treated as independent. Timmy has no memory of prior exchanges within the same session. Adding conversation context means follow-ups like 'now make it shorter' work naturally.

Done looks like

  • Within a funded session, the last N exchanges (default 8) are passed as conversation history to the work model
  • Timmy's replies reference prior context naturally
  • Session history stored in DB and retrieved per session ID
  • History capped at 4k token budget to prevent cost runaway
  • History resets when session expires or is explicitly cleared
  • A 'clear history' button appears in the session panel

Out of scope

  • Cross-session memory (separate knowledge base task)
  • Free tier chat context (stateless)
  • Changing session payment or expiry logic

Tasks

  1. Session conversation table — Add session_messages table (session_id, role, content, token_count, created_at); retrieval function returns last N messages within token budget.
  2. Context injection — Prepend session conversation history when building work prompt; append completed response to history after execution.
  3. History management — Token budget enforcement, expiry-based cleanup; expose /api/session/:id/history/clear endpoint.
  4. Frontend clear button — 'Clear history' affordance in session panel that calls clear endpoint with confirmation.

Relevant files

  • artifacts/api-server/src/lib/agent.ts
  • artifacts/api-server/src/routes/jobs.ts
  • artifacts/api-server/src/routes/sessions.ts
  • the-matrix/js/session.js
  • the-matrix/js/ui.js
## What & Why In session mode, each job is currently treated as independent. Timmy has no memory of prior exchanges within the same session. Adding conversation context means follow-ups like 'now make it shorter' work naturally. ## Done looks like - Within a funded session, the last N exchanges (default 8) are passed as conversation history to the work model - Timmy's replies reference prior context naturally - Session history stored in DB and retrieved per session ID - History capped at 4k token budget to prevent cost runaway - History resets when session expires or is explicitly cleared - A 'clear history' button appears in the session panel ## Out of scope - Cross-session memory (separate knowledge base task) - Free tier chat context (stateless) - Changing session payment or expiry logic ## Tasks 1. **Session conversation table** — Add `session_messages` table (session_id, role, content, token_count, created_at); retrieval function returns last N messages within token budget. 2. **Context injection** — Prepend session conversation history when building work prompt; append completed response to history after execution. 3. **History management** — Token budget enforcement, expiry-based cleanup; expose `/api/session/:id/history/clear` endpoint. 4. **Frontend clear button** — 'Clear history' affordance in session panel that calls clear endpoint with confirmation. ## Relevant files - `artifacts/api-server/src/lib/agent.ts` - `artifacts/api-server/src/routes/jobs.ts` - `artifacts/api-server/src/routes/sessions.ts` - `the-matrix/js/session.js` - `the-matrix/js/ui.js`
replit added the workshopbackendfrontendai labels 2026-03-20 22:21:35 +00:00
claude was assigned by Rockachopa 2026-03-22 23:37:57 +00:00
Collaborator

PR created: http://143.198.27.163:3000/replit/timmy-tower/pulls/92

All conversation context pieces were already implemented (DB table, migration, getSessionHistory with token budget, context injection in the request handler, frontend clear button). The only missing piece was the DELETE /sessions/:id/history backend endpoint — added in this PR. It requires macaroon auth and deletes all session_messages rows for the session.

PR created: http://143.198.27.163:3000/replit/timmy-tower/pulls/92 All conversation context pieces were already implemented (DB table, migration, getSessionHistory with token budget, context injection in the request handler, frontend clear button). The only missing piece was the `DELETE /sessions/:id/history` backend endpoint — added in this PR. It requires macaroon auth and deletes all session_messages rows for the session.
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: replit/timmy-tower#3