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): improve memory prompt + disambiguate team tool with job title (#4015)

Eric Hayes5ff3983053ae
diff --git a/js/app/packages/service-clients/service-cognition/generated/tools/types.ts b/js/app/packages/service-clients/service-cognition/generated/tools/types.ts
index 0938ec16ce..bc97b58c24 100644
--- a/js/app/packages/service-clients/service-cognition/generated/tools/types.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/tools/types.ts
@@ -1476,7 +1476,7 @@ export interface NotificationItem {
senderId?: string | null;
}
/**
- * List the current members and pending invites for the authenticated user's team. Requires the caller to be a team member.
+ * List the current members and pending invites for the authenticated user's team. Requires the caller to be a team member. The returned roles (owner/admin/member) are app permission levels only, not job titles — they say nothing about the org chart. Never infer that someone is a founder, an executive, or the company's owner from their workspace role.
*/
export type ListTeamMembers = {};
/**
@@ -1501,7 +1501,8 @@ export interface ToolTeamInvite {
*/
email: string;
/**
- * The role the invited user will receive.
+ * The workspace permission role (owner/admin/member) the invited user
+ * will receive. An app permission level, not a job title.
*/
role: string;
}
@@ -1510,7 +1511,8 @@ export interface ToolTeamInvite {
*/
export interface ToolTeamMember {
/**
- * The user's role in the team.
+ * The user's workspace permission role (owner/admin/member). An app
+ * permission level, not a job title or evidence of company ownership.
*/
role: string;
/**
diff --git a/rust/cloud-storage/memory/src/domain/service.rs b/rust/cloud-storage/memory/src/domain/service.rs
index fac4a1cf2b..c0c47c2580 100644
--- a/rust/cloud-storage/memory/src/domain/service.rs
+++ b/rust/cloud-storage/memory/src/domain/service.rs
@@ -32,10 +32,18 @@ unsupported details.
Don't include things that would make sense to find via tool search at runtime. \
Focus on context that is useful as permanent background knowledge.
-CRITICAL: Your response must contain ONLY the memory text. \
-No preamble, no postscript, no commentary, no \"Let me...\", no \"Here is...\". \
-Do not narrate your research process. Do not address the user. \
-Just output the raw memory text starting with the first substantive line.";
+Only state a corporate title or founder status when content written by people \
+(documents, emails, bios, announcements) states it explicitly; otherwise \
+describe what the person works on and skip the title. This applies to titles \
+inherited from the previous memory too — a title you can't re-confirm from \
+content gets dropped, not preserved.
+
+Output format: wrap the finished memory in <memory></memory> tags. Everything \
+outside the tags is discarded, and a response without the tags is rejected \
+entirely. Inside the tags, write only the memory itself — no preamble, no \
+postscript, no commentary, no narration of your research process (\"I have \
+enough context\", \"Let me write the memory\", \"Now I have a comprehensive \
+picture\"), and no text addressed to the user.";
static JUDGE_PROMPT: &str = "\
You are a strict quality judge for AI-generated user memory profiles.
@@ -55,7 +63,9 @@ REJECT if ANY of the following are true:
- It lacks specific details about the user's actual work, codebase, projects, or role.
- It reads like a personality quiz rather than a professional profile grounded in \
real workspace activity.
-- It contains narration about the research process (\"I found...\", \"The workspace has...\").
+- It contains the generator's narration or self-talk anywhere in the text \
+ (\"I have enough context\", \"Let me write the memory\", \"I need to research\", \
+ \"Now I have a comprehensive picture\", \"I found...\", \"The workspace has...\").
ACCEPT only if the memory contains concrete, specific, actionable context derived \
from substantial workspace data (documents, code, projects, emails, messages) that \
@@ -187,7 +197,13 @@ where
}
}
- let memory = content.trim().to_string();
+ let Some(memory) = extract_memory_body(&content).map(str::to_string) else {
+ tracing::warn!(
+ content_len = content.len(),
+ "generation output missing <memory> tags"
+ );
+ return Err(MemoryError::NoGeneration);
+ };
if memory.is_empty() {
return Err(MemoryError::NoGeneration);
}
@@ -200,6 +216,17 @@ where
}
}
+/// Extract the memory body from the agent's final message.
+///
+/// The generation prompt requires the memory to be wrapped in <memory> tags so
+/// that any narration the model emits around it is discarded deterministically
+/// rather than trusting the model to suppress it.
+fn extract_memory_body(content: &str) -> Option<&str> {
+ let start = content.find("<memory>")? + "<memory>".len();
+ let end = content.rfind("</memory>")?;
+ content.get(start..end).map(str::trim)
+}
+
fn build_generation_system_prompt(
base_prompt: impl std::fmt::Display,
user: &macro_user_id::user_id::MacroUserIdStr<'_>,
@@ -268,6 +295,32 @@ mod tests {
assert!(prompt.contains("<previous_memory>\nprevious durable facts\n</previous_memory>"));
}
+ #[test]
+ fn extract_memory_body_strips_surrounding_narration() {
+ let content = "I have enough context. Let me write the memory.\n\
+ <memory>\nEric is an engineer at Macro.\n</memory>\nDone!";
+ assert_eq!(
+ extract_memory_body(content),
+ Some("Eric is an engineer at Macro.")
+ );
+ }
+
+ #[test]
+ fn extract_memory_body_rejects_missing_tags() {
+ assert_eq!(extract_memory_body("Eric is an engineer at Macro."), None);
+ assert_eq!(extract_memory_body("<memory>unterminated"), None);
+ assert_eq!(extract_memory_body("</memory>backwards<memory>"), None);
+ }
+
+ #[test]
+ fn extract_memory_body_uses_last_closing_tag() {
+ let content = "<memory>uses </memory> in prose</memory>";
+ assert_eq!(
+ extract_memory_body(content),
+ Some("uses </memory> in prose")
+ );
+ }
+
#[test]
fn generation_system_prompt_omits_previous_memory_when_absent() {
let user = user_id("macro|[email protected]");
diff --git a/rust/cloud-storage/teams/src/inbound/toolset/list_team_members.rs b/rust/cloud-storage/teams/src/inbound/toolset/list_team_members.rs
index 40fb23eeb0..0bcc9ee0b4 100644
--- a/rust/cloud-storage/teams/src/inbound/toolset/list_team_members.rs
+++ b/rust/cloud-storage/teams/src/inbound/toolset/list_team_members.rs
@@ -22,7 +22,8 @@ use serde::{Deserialize, Serialize};
pub struct ToolTeamMember {
/// The user's Macro user id.
pub user_id: String,
- /// The user's role in the team.
+ /// The user's workspace permission role (owner/admin/member). An app
+ /// permission level, not a job title or evidence of company ownership.
pub role: String,
}
@@ -41,7 +42,8 @@ impl From<TeamMember<'static>> for ToolTeamMember {
pub struct ToolTeamInvite {
/// The invited email address.
pub email: String,
- /// The role the invited user will receive.
+ /// The workspace permission role (owner/admin/member) the invited user
+ /// will receive. An app permission level, not a job title.
pub role: String,
}
@@ -68,7 +70,7 @@ pub struct ListTeamMembersResponse {
#[derive(Debug, Deserialize, JsonSchema, Clone, Default)]
#[schemars(
title = "ListTeamMembers",
- description = "List the current members and pending invites for the authenticated user's team. Requires the caller to be a team member."
+ description = "List the current members and pending invites for the authenticated user's team. Requires the caller to be a team member. The returned roles (owner/admin/member) are app permission levels only, not job titles — they say nothing about the org chart. Never infer that someone is a founder, an executive, or the company's owner from their workspace role."
)]
#[allow(unused)]
// empty structs can't be deserialized;