refactor: remove MEMORY.md from prompt, add AgentCore memory instructions
This commit is contained in:
@@ -46,25 +46,8 @@ def _get_base_prompt(actor_id: str = '') -> str:
|
|||||||
s3 = boto3.client('s3')
|
s3 = boto3.client('s3')
|
||||||
parts = []
|
parts = []
|
||||||
|
|
||||||
# Per-user MEMORY.md (falls back to global)
|
# MEMORY.md removed — AgentCore Memory handles persistent facts via conversation history.
|
||||||
memory_key = f'users/{actor_id}/MEMORY.md' if actor_id else 'MEMORY.md'
|
# Long-term memory extraction (retrieval_config + memory strategy) is the right layer for this.
|
||||||
try:
|
|
||||||
obj = s3.get_object(Bucket=bucket, Key=memory_key)
|
|
||||||
content = obj['Body'].read().decode('utf-8')
|
|
||||||
parts.append(f'## MEMORY.md\n{content}')
|
|
||||||
print(f'[prompt_builder] Loaded {memory_key} ({len(content)} bytes)')
|
|
||||||
except ClientError as e:
|
|
||||||
if e.response['Error']['Code'] in ('NoSuchKey', 'AccessDenied') and actor_id:
|
|
||||||
# Fall back to global MEMORY.md
|
|
||||||
try:
|
|
||||||
obj = s3.get_object(Bucket=bucket, Key='MEMORY.md')
|
|
||||||
content = obj['Body'].read().decode('utf-8')
|
|
||||||
parts.append(f'## MEMORY.md\n{content}')
|
|
||||||
print(f'[prompt_builder] Loaded MEMORY.md (fallback, {len(content)} bytes)')
|
|
||||||
except Exception as e2:
|
|
||||||
print(f'[prompt_builder] Failed to load MEMORY.md: {e2}')
|
|
||||||
else:
|
|
||||||
print(f'[prompt_builder] Failed to load {memory_key}: {e}')
|
|
||||||
|
|
||||||
for fname in ['SOUL.md', 'AGENTS.md', 'IDENTITY.md', 'TOOLS.md', 'HEARTBEAT.md']:
|
for fname in ['SOUL.md', 'AGENTS.md', 'IDENTITY.md', 'TOOLS.md', 'HEARTBEAT.md']:
|
||||||
try:
|
try:
|
||||||
@@ -75,6 +58,24 @@ def _get_base_prompt(actor_id: str = '') -> str:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'[prompt_builder] Failed to load {fname}: {e}')
|
print(f'[prompt_builder] Failed to load {fname}: {e}')
|
||||||
|
|
||||||
|
parts.append(
|
||||||
|
'## Memory\n'
|
||||||
|
'Your memory works through two layers:\n\n'
|
||||||
|
'**Conversation history (short-term):** AgentCore automatically loads your full '
|
||||||
|
'conversation history with this user at the start of each session. You have complete '
|
||||||
|
'context of everything discussed previously — no need to ask users to repeat themselves.\n\n'
|
||||||
|
'**Long-term facts (LTM):** Important facts extracted from past conversations are '
|
||||||
|
'retrieved and injected as context automatically. These are things like preferences, '
|
||||||
|
'setup details, names, and recurring topics the user has shared.\n\n'
|
||||||
|
'Guidelines:\n'
|
||||||
|
'- Never ask "what did we discuss last time?" — you already have the history.\n'
|
||||||
|
'- When a user shares something important (job interview, preference, key decision, '
|
||||||
|
'setup change), acknowledge it and trust it will be captured — do not ask if they '
|
||||||
|
'want you to remember it.\n'
|
||||||
|
'- If you notice a fact that seems important but may not be in LTM yet (e.g. a '
|
||||||
|
'deadline, a preference, a name), you may say "I\'ll keep that in mind" — but do '
|
||||||
|
'not ask permission or make a production of it.'
|
||||||
|
)
|
||||||
parts.append('## Runtime\nRuntime: agent-claw | host=AgentCore | model=bedrock-claude-sonnet | channel=telegram | timezone=America/Chicago')
|
parts.append('## Runtime\nRuntime: agent-claw | host=AgentCore | model=bedrock-claude-sonnet | channel=telegram | timezone=America/Chicago')
|
||||||
|
|
||||||
result = '\n\n---\n\n'.join(parts)
|
result = '\n\n---\n\n'.join(parts)
|
||||||
|
|||||||
Reference in New Issue
Block a user