From aa4513d4f8ebaa5b34748430477af5cc89e661b0 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Wed, 3 Jun 2026 16:38:51 +0800 Subject: [PATCH] feat(observe): enhance runtime context with communication and final answer instructions - Added detailed communication and final answer instructions to the runtime context block, guiding the model on user-facing text and tool usage. - Updated the XML structure to reflect these changes, ensuring clarity on metadata and instructions for each turn. - Improved the overall safety and clarity of the model's output by preventing the exposure of internal tool names and IDs. --- internal/agent/observe.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/agent/observe.go b/internal/agent/observe.go index baf9218b..64ce4211 100644 --- a/internal/agent/observe.go +++ b/internal/agent/observe.go @@ -292,6 +292,10 @@ func escapeXMLAttr(s string) string { // model see exactly which KBs were in scope at the time of each historical // turn. // +// Per-turn communication_instruction and final_answer_instruction remind the +// model not to leak internal tool names or IDs in user-visible text, and to +// always end the turn via final_answer. +// // Emitted as an XML-ish block (not free prose) so it is a visually distinct, // non-instruction envelope that is hard to conflate with user text and // prompt-injection-safe. @@ -301,7 +305,7 @@ func buildRuntimeContextBlock( docs []*SelectedDocumentInfo, ) string { var sb strings.Builder - sb.WriteString("\n") + sb.WriteString("\n") fmt.Fprintf(&sb, " %s\n", time.Now().Format(time.RFC3339)) fmt.Fprintf(&sb, " %s\n", escapeXMLAttr(sessionID)) @@ -337,6 +341,9 @@ func buildRuntimeContextBlock( sb.WriteString(" The pinned-document set above is authoritative for THIS turn. If an earlier turn in this conversation analysed a different document, do NOT reuse that analysis — re-query against the current scope.\n") } + sb.WriteString(" Do not use internal tool names or identifiers in your answers or in Thought. Say \"keyword retrieval\" instead of grep_chunks, \"semantic retrieval\" instead of knowledge_search, \"browse full document\" instead of list_knowledge_chunks; likewise never expose chunk_id, knowledge_id, or other internal IDs—refer to documents by title or name.\n") + sb.WriteString(" When you are ready to respond, you MUST call the final_answer tool with your complete user-facing answer—never end a turn with plain assistant text or skip this step.\n") + sb.WriteString("") return sb.String() }