sdac-log-conversation-turn
Purpose
Logs a single conversation turn (user message or assistant response) to SDAC.fact_ConversationHistory. Provides a durable audit trail of every exchange in a review session and makes history available for context hydration via sdac-get-conversation-history.
Tool type
Deterministic (write)
Tool ID
sdac-log-conversation-turn
Inputs
conversationId(string, required) -- Session ID fromsdac-start-conversationreportId(string, required, UUID) -- Cost report IDuserId(string, required) -- User identifierrole(user|assistant, required) -- Message rolemessageContent(string, required) -- Message text contentturnNumber(number, optional) -- Specific turn number; auto-incremented from the last logged turn if omittedpersonnelId(number, optional) -- If the turn relates to a specific personnel recordruleId(string, optional) -- If the turn relates to a specific validation rulemodelUsed(string, optional) -- AI model used for assistant responses (for analytics)promptTokens(number, optional) -- Prompt token countcompletionTokens(number, optional) -- Completion token count
Outputs
logged(boolean) -- Alwaystrueon successconversationSK(number) -- Database primary key of the inserted recordturnNumber(number) -- The turn number that was assigned
Example output
{
"logged": true,
"conversationSK": 1289,
"turnNumber": 5
}
Functional details
- If
turnNumberis omitted, the tool reads the current maximum turn number for the conversation and increments by 1. totalTokensis computed aspromptTokens + completionTokenswhen both are provided.- The returned
conversationSKcan be passed tosdac-store-feedbackto anchor user feedback to a specific turn.
Usage notes
- Log both sides of every exchange: call once for the user message and once for the assistant response.
- Include
modelUsedand token counts on assistant turns for cost and performance analytics. - Part of the session management trio:
sdac-start-conversation→sdac-get-conversation-history→sdac-log-conversation-turn.
Implementation details
- Writes to
SDAC.fact_ConversationHistoryvia theinsertConversationTurnDB helper.
Code Location: packages/domain-sdac/src/tools/session/log-conversation-turn.tool.ts