diff --git a/workspace/claude_sdk_executor.py b/workspace/claude_sdk_executor.py index 76421a46..8569fb60 100644 --- a/workspace/claude_sdk_executor.py +++ b/workspace/claude_sdk_executor.py @@ -49,6 +49,7 @@ from executor_helpers import ( commit_memory, extract_message_text, get_a2a_instructions, + get_hma_instructions, get_mcp_server_path, get_system_prompt, read_delegation_results, @@ -210,12 +211,12 @@ class ClaudeSDKExecutor(AgentExecutor): return CONFIG_MOUNT def _build_system_prompt(self) -> str | None: - """Compose system prompt from file + A2A delegation instructions.""" + """Compose system prompt from file + A2A + HMA memory instructions.""" base = get_system_prompt(self.config_path, fallback=self.system_prompt) a2a = get_a2a_instructions(mcp=True) - if base and a2a: - return f"{base}\n\n{a2a}" - return base or a2a + hma = get_hma_instructions() + parts = [p for p in (base, a2a, hma) if p] + return "\n\n".join(parts) if parts else None def _prepare_prompt(self, user_input: str) -> str: """Prepend delegation results that arrived while idle.""" diff --git a/workspace/executor_helpers.py b/workspace/executor_helpers.py index 848dd6a2..ce165bfd 100644 --- a/workspace/executor_helpers.py +++ b/workspace/executor_helpers.py @@ -288,6 +288,31 @@ def get_a2a_instructions(mcp: bool = True) -> str: return _A2A_INSTRUCTIONS_MCP if mcp else _A2A_INSTRUCTIONS_CLI +_HMA_INSTRUCTIONS = """## Hierarchical Memory (HMA) +You have persistent memory tools that survive across sessions and restarts: + +- **commit_memory(content, scope)**: Save important information. + - LOCAL: private to you only (default) + - TEAM: shared with your parent workspace and siblings (same team) + - GLOBAL: shared with the entire org (only root workspaces can write) + +- **recall_memory(query)**: Search your accessible memories. Returns LOCAL + TEAM + GLOBAL matches. + +**When to use memory:** +- After making a decision or learning something non-obvious → commit_memory("decision X because Y", scope="TEAM") +- Before starting work → recall_memory("what did the team decide about X") +- When you discover org-wide knowledge (repo locations, API patterns, conventions) → commit_memory(fact, scope="GLOBAL") if you are a root workspace, or scope="TEAM" to share with your team +- After completing a task → commit_memory("completed task X, PR #N opened", scope="TEAM") so your lead and teammates know + +**Memory is automatically recalled** at the start of each new session. Use it proactively during work to share context. +""" + + +def get_hma_instructions() -> str: + """Return HMA memory instructions for system-prompt injection.""" + return _HMA_INSTRUCTIONS + + # ======================================================================== # Misc text helpers # ========================================================================