feat(runtime): inject HMA memory instructions at platform level (#1047)
Every agent now gets hierarchical memory instructions in their system prompt automatically — no template configuration needed. Instructions cover commit_memory (LOCAL/TEAM/GLOBAL scopes), recall_memory, and when to use each proactively. Follows the same pattern as A2A instructions: defined in executor_helpers.py, injected by _build_system_prompt() in the claude_sdk_executor. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
cb46c97d42
commit
ae2c05d6f0
@ -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."""
|
||||
|
||||
@ -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
|
||||
# ========================================================================
|
||||
|
||||
Loading…
Reference in New Issue
Block a user