From 000f46a30a8456a499eddbf4d8b7e092cc4ecbd2 Mon Sep 17 00:00:00 2001 From: Luis Novo Date: Thu, 21 May 2026 21:27:30 -0300 Subject: [PATCH] fix: inject notebook name and description into chat system prompt (#719) The chat system prompt template had a conditional block for notebook metadata but the /chat/execute endpoint never populated it. Fetch the notebook linked to the session via the refers_to relationship and pass it to the graph state so the LLM receives the notebook's name and description as project context. Closes #685 --- api/routers/chat.py | 10 ++++++++++ prompts/chat/system.jinja | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/api/routers/chat.py b/api/routers/chat.py index 8abe6694..abeeab82 100644 --- a/api/routers/chat.py +++ b/api/routers/chat.py @@ -342,6 +342,15 @@ async def execute_chat(request: ExecuteChatRequest): if not session: raise HTTPException(status_code=404, detail="Session not found") + # Fetch notebook linked to this session + notebook_query = await repo_query( + "SELECT out FROM refers_to WHERE in = $session_id", + {"session_id": ensure_record_id(full_session_id)}, + ) + notebook = None + if notebook_query: + notebook = await Notebook.get(notebook_query[0]["out"]) + # Determine model override (per-request override takes precedence over session-level) model_override = ( request.model_override @@ -360,6 +369,7 @@ async def execute_chat(request: ExecuteChatRequest): state_values = current_state.values if current_state else {} state_values["messages"] = state_values.get("messages", []) state_values["context"] = request.context + state_values["notebook"] = notebook state_values["model_override"] = model_override # Add user message to state diff --git a/prompts/chat/system.jinja b/prompts/chat/system.jinja index dab2eda2..f56e75be 100644 --- a/prompts/chat/system.jinja +++ b/prompts/chat/system.jinja @@ -11,7 +11,8 @@ Whenever a user asks you a question, you need to identify the query context and {% if notebook %} # PROJECT INFORMATION -{{notebook}} +**Name:** {{notebook.name}} +**Description:** {{notebook.description}} {% endif %} {% if context %}