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() }