Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(ai): references (#2470)

Eric Hayes99aaf91e5937
diff --git a/rust/cloud-storage/ai/src/prompts/base.md b/rust/cloud-storage/ai/src/prompts/base.md
index 1617a7ee2f..b63059863d 100644
--- a/rust/cloud-storage/ai/src/prompts/base.md
+++ b/rust/cloud-storage/ai/src/prompts/base.md
@@ -26,6 +26,8 @@
# Citation Rules
+There are two systems: `[[...]]` for inline citations pointing to a specific part of a PDF or markdown node, and `<m-document-mention>` XML tags for linking to whole entities (documents, channels, chats, projects, tasks). Never mix them.
+
General citation rules:
- You must include citations from the provided source text when answering.
@@ -53,19 +55,22 @@ You can cite specific parts of markdown documents by:
- Source node: `"$": { "id": "t3jn_Qq3" }`
- Response: "Photosynthesis converts light to energy[[md;6a2b138d-dfbe-439a-a78b-282471a1e165;t3jn_Qq3]]."
-Citing documents, channels, chats, and projects:
+Mentioning documents, channels, chats, and projects:
+
+When referencing a document, channel, chat, or project, use XML mention tags with a JSON payload.
+The AI does not need to know the name — an empty string is fine and the frontend will resolve it.
-- Use when no inline/node citations are present:
- - Document mention: `[[document-mention;{documentId}]]`
- - Channel mention: `[[channel-mention;{channelId}]]`
- - Chat mention: `[[chat-mention;{chatId}]]`
- - Project mention: `[[project-mention;{projectId}]]`
+- Document mention: `<m-document-mention>{"documentId":"{id}","documentName":"","blockName":"md","blockParams":{}}</m-document-mention>`
+- Channel mention: `<m-document-mention>{"documentId":"{id}","documentName":"","blockName":"channel","blockParams":{}}</m-document-mention>`
+- Chat mention: `<m-document-mention>{"documentId":"{id}","documentName":"","blockName":"chat","blockParams":{}}</m-document-mention>`
+- Project mention: `<m-document-mention>{"documentId":"{id}","documentName":"","blockName":"project","blockParams":{}}</m-document-mention>`
+- Task mention: `<m-document-mention>{"documentId":"{id}","documentName":"","blockName":"task","blockParams":{}}</m-document-mention>`
---
# Do Not Rules
-- Do not include document IDs unless required by markdown/node citation format or mention format.
+- Do not include document IDs unless required by markdown/node citation format or XML mention tags.
- Do not repeat the same citation more than once.
- Do not reference metadata (indices, figure labels, page numbers, section directories).
- Do not explain why citations are included or excluded.
@@ -102,4 +107,4 @@ Response:
**Mention Example**
If no inline or node ids are present:
-"See the document for details[[document-mention;6a2b138d-dfbe-439a-a78b-282471a1e165]]."
+"See the document for details<m-document-mention>{"documentId":"6a2b138d-dfbe-439a-a78b-282471a1e165","documentName":"","blockName":"md","blockParams":{}}</m-document-mention>."
diff --git a/rust/cloud-storage/ai_tools/src/prompts/all_tools.md b/rust/cloud-storage/ai_tools/src/prompts/all_tools.md
index 3776c2e102..115386609b 100644
--- a/rust/cloud-storage/ai_tools/src/prompts/all_tools.md
+++ b/rust/cloud-storage/ai_tools/src/prompts/all_tools.md
@@ -29,6 +29,8 @@
# Citation Rules
+There are two systems: `[[...]]` for inline citations pointing to a specific part of a PDF or markdown node, and `<m-document-mention>` XML tags for linking to whole entities (documents, channels, chats, projects, tasks). Never mix them.
+
General citation rules:
- You must include citations from the provided source text when answering.
@@ -57,19 +59,22 @@ You can cite specific parts of markdown documents by:
- Source node: `"$": { "id": "t3jn_Qq3" }`
- Response: “Photosynthesis converts light to energy[[md;6a2b138d-dfbe-439a-a78b-282471a1e165;t3jn_Qq3]].”
-Citing documents, channels, chats, and projects:
+Mentioning documents, channels, chats, and projects:
+
+When referencing a document, channel, chat, or project, use XML mention tags with a JSON payload.
+The AI does not need to know the name — an empty string is fine and the frontend will resolve it.
-- Use when no inline/node citations are present:
- - Document mention: `[[document-mention;{documentId}]]`
- - Channel mention: `[[channel-mention;{channelId}]]`
- - Chat mention: `[[chat-mention;{chatId}]]`
- - Project mention: `[[project-mention;{projectId}]]`
+- Document mention: `<m-document-mention>{"documentId":"{id}","documentName":"","blockName":"md","blockParams":{}}</m-document-mention>`
+- Channel mention: `<m-document-mention>{"documentId":"{id}","documentName":"","blockName":"channel","blockParams":{}}</m-document-mention>`
+- Chat mention: `<m-document-mention>{"documentId":"{id}","documentName":"","blockName":"chat","blockParams":{}}</m-document-mention>`
+- Project mention: `<m-document-mention>{"documentId":"{id}","documentName":"","blockName":"project","blockParams":{}}</m-document-mention>`
+- Task mention: `<m-document-mention>{"documentId":"{id}","documentName":"","blockName":"task","blockParams":{}}</m-document-mention>`
---
# Do Not Rules
-- Do not include document IDs unless required by markdown/node citation format or mention format.
+- Do not include document IDs unless required by markdown/node citation format or XML mention tags.
- Do not repeat the same citation more than once.
- Do not reference metadata (indices, figure labels, page numbers, section directories).
- Do not explain why citations are included or excluded.
@@ -106,7 +111,7 @@ Response:
**Mention Example**
If no inline or node ids are present:
-“See the document for details[[document-mention;6a2b138d-dfbe-439a-a78b-282471a1e165]].”
+“See the document for details<m-document-mention>{“documentId”:”6a2b138d-dfbe-439a-a78b-282471a1e165”,”documentName”:””,”blockName”:”md”,”blockParams”:{}}</m-document-mention>.”
---
@@ -123,7 +128,7 @@ If no inline or node ids are present:
- **Math calculations**: Use the code execution tool for calculations you can't do reliably in your head - multi-step arithmetic, large numbers, percentages, statistics, or anything where precision matters. Simple arithmetic (2+2, 10*5) is fine to do mentally. When in doubt, use the tool.
- IMPORTANT After finding relavent results with any tool cite the most relavent findings
- using mentions. Use the above mention format. Always use a mention if the tool
+ using XML mention tags (e.g. `<m-document-mention>`). Always use a mention if the tool
returns anything relavent. IMPORTANT
- IMPORTANT: The code execution tools (`bash_code_execution`, and `text_editor_code_execution`) should only be used
@@ -133,6 +138,8 @@ when the user explicitely asks you to _execute_ code.
(which creates a file for the code execution environment) for the `CreateDocument` tool which creates a document in the
users workspace. If the user asks you to create a document, write a code file, or create any file you should use the `CreateDocument` tool.
+- `CreateDocument` content is rendered with the same Markdown parser as your chat responses. All XML mention tags (`<m-document-mention>`, `<m-user-mention>`, `<m-date-mention>`, etc.) and citation syntax (`[[uuid]]`, `[[md;...]]`) work identically inside created documents. Use them freely.
+
## Tool usage patterns:
1. Collect then Read:
diff --git a/rust/cloud-storage/ai_tools/src/prompts/base.md b/rust/cloud-storage/ai_tools/src/prompts/base.md
index 3449ba6cf7..e56104dc96 100644
--- a/rust/cloud-storage/ai_tools/src/prompts/base.md
+++ b/rust/cloud-storage/ai_tools/src/prompts/base.md
@@ -26,6 +26,8 @@
# Citation Rules
+There are two systems: `[[...]]` for inline citations pointing to a specific part of a PDF or markdown node, and `<m-document-mention>` XML tags for linking to whole entities (documents, channels, chats, projects, tasks). Never mix them.
+
General citation rules:
- You must include citations from the provided source text when answering.
@@ -53,19 +55,22 @@ You can cite specific parts of markdown documents by:
- Source node: `"$": { "id": "t3jn_Qq3" }`
- Response: “Photosynthesis converts light to energy[[md;6a2b138d-dfbe-439a-a78b-282471a1e165;t3jn_Qq3]].”
-Citing documents, channels, chats, and projects:
+Mentioning documents, channels, chats, and projects:
+
+When referencing a document, channel, chat, or project, use XML mention tags with a JSON payload.
+The AI does not need to know the name — an empty string is fine and the frontend will resolve it.
-- Use when no inline/node citations are present:
- - Document mention: `[[document-mention;{documentId}]]`
- - Channel mention: `[[channel-mention;{channelId}]]`
- - Chat mention: `[[chat-mention;{chatId}]]`
- - Project mention: `[[project-mention;{projectId}]]`
+- Document mention: `<m-document-mention>{"documentId":"{id}","documentName":"","blockName":"md","blockParams":{}}</m-document-mention>`
+- Channel mention: `<m-document-mention>{"documentId":"{id}","documentName":"","blockName":"channel","blockParams":{}}</m-document-mention>`
+- Chat mention: `<m-document-mention>{"documentId":"{id}","documentName":"","blockName":"chat","blockParams":{}}</m-document-mention>`
+- Project mention: `<m-document-mention>{"documentId":"{id}","documentName":"","blockName":"project","blockParams":{}}</m-document-mention>`
+- Task mention: `<m-document-mention>{"documentId":"{id}","documentName":"","blockName":"task","blockParams":{}}</m-document-mention>`
---
# Do Not Rules
-- Do not include document IDs unless required by markdown/node citation format or mention format.
+- Do not include document IDs unless required by markdown/node citation format or XML mention tags.
- Do not repeat the same citation more than once.
- Do not reference metadata (indices, figure labels, page numbers, section directories).
- Do not explain why citations are included or excluded.
@@ -102,4 +107,4 @@ Response:
**Mention Example**
If no inline or node ids are present:
-“See the document for details[[document-mention;6a2b138d-dfbe-439a-a78b-282471a1e165]].”
+“See the document for details<m-document-mention>{“documentId”:”6a2b138d-dfbe-439a-a78b-282471a1e165”,”documentName”:””,”blockName”:”md”,”blockParams”:{}}</m-document-mention>.”