AI SystemLLM System
Answer Generation
The generator agent produces the final answer to the user. It runs last on every answered turn, whichever path the question took.
- One generator for both paths: the SQL path and the RAG path use the same agent. Only the context differs: the SQL rows or the retrieved pieces.
- Structured output (Pydantic model): the answer and, on the RAG path, the piece ids. The answer is declared first, so the text streams before the ids; in the other order the user would wait for the ids before seeing any text.
- Sources (RAG path):
- Named by the model: the prompt tells it to list the id of every piece a fact in its answer came from, and to cite nothing that did not contribute.
- Checked against the context: ClayDiary keeps only the ids that were in the context the model received. An id the model never saw is a fabrication and is dropped. The check cannot ask the model to retry, because the answer has already streamed.
- Consulted and cited: consulted pieces are all the pieces in the context, and cited pieces are the ones the model named. The interface shows the cited ones. SQL answers, refusals and errors have no sources. The turn's trace records both counts.
- Streamed: the answer is sent to the browser as it is written. PydanticAI returns the growing answer object each time, so ClayDiary sends only the new text.
- If generation fails: the user gets a fixed error message instead of an answer.
The system prompts are versioned; see Prompt Management.