[Session] Context injection — pass conversation history to work model #39
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
When executing a session work request, prepend the session's prior conversation history to the prompt, and append the completed exchange to history after the response is produced.
Depends on: #38 (session_messages table)
Why
With the table in place but no injection, Timmy still cannot reference prior context. This ticket wires the stored history into the AI call so follow-ups like "now make it shorter" work naturally.
Where to change
artifacts/api-server/src/routes/sessions.ts—POST /sessions/:id/requestStep 1 — Load history before eval (line ~315)
Step 2 — Change executeWork call (line ~346)
Add a
conversationHistoryparameter toAgentService.executeWork(and the streaming variant) so the Anthropicmessagesarray receives all prior turns:In
agent.ts, build the messages array:Pass
messagestoclient.messages.create({ ..., messages }).Step 3 — Append exchange to history after completion (line ~428, inside the DB transaction)
Only insert on
finalState === "complete"— rejected/failed requests are not persisted to history.Relevant files
artifacts/api-server/src/routes/sessions.tsartifacts/api-server/src/lib/agent.tspackages/db/src/index.ts(getSessionHistory helper from #38)Acceptance
PR #78 created.
Changes:
session_messagestable + migration for storing conversation turnsgetSessionHistory()helper with turn count and token budget limitsexecuteWork()andexecuteWorkStreaming()via optionalconversationHistoryparameterPOST /sessions/:id/requestnow loads history before the work call and persists user+assistant messages atomically — only on completed requests