fix: pass agentId per-call for integration-scoped memory#665
Conversation
|
@chdlc is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (8)
📝 WalkthroughWalkthroughAgentMemory now prefers AGENTMEMORY_AGENT_ID (falling back to AGENT_ID) and conditionally forwards an agentId field in memory-related requests across Hermes, OpenClaw, and MCP flows; README and tests updated to cover sourcing, precedence, and forwarding behavior. ChangesAgent ID propagation and tests
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
b83d692 to
04ad752
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
README.md (1)
1141-1188: ⚡ Quick winClarify the distinction between server default and per-client agent identity.
The documentation covers the technical details but mixes server-side configuration (
AGENT_IDin~/.agentmemory/.env) with client-side configuration (AGENTMEMORY_AGENT_IDin integration/MCP env) without clearly explaining why you'd use one vs the other. Consider restructuring this section to:
Lead with the use case distinction before diving into examples:
AGENT_ID: Set once in the agentmemory server's~/.agentmemory/.envwhen you run a single-role server (e.g., "architect" server)AGENTMEMORY_AGENT_ID: Set per-client/integration when multiple clients with different roles share one agentmemory server (e.g., Hermes "architect", OpenClaw "reviewer", MCP "researcher" all connecting to the same server)Make precedence rules more prominent — the statement "If both
AGENTMEMORY_AGENT_IDandAGENT_IDare present in the same process,AGENTMEMORY_AGENT_IDwins" (line 1172) is buried. Surface it earlier or in a callout.Clarify "When no agent id is set" (line 1187) — does this mean neither variable is set in any process, or just not set in a specific context? Be explicit: "When neither
AGENT_IDnorAGENTMEMORY_AGENT_IDis set..."Group examples by deployment scenario rather than by variable:
- "Single-role server" (just
AGENT_ID)- "Multi-client shared server" (
AGENTMEMORY_AGENT_IDper client)- "Per-request overrides" (body field in API calls)
This is documentation-only, so no runtime impact, but clearer structure reduces user confusion when choosing which variable to set.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@README.md` around lines 1141 - 1188, The docs mix server-side vs client-side config—restructure the Multi-agent memory section to lead with use-case distinction (explain AGENT_ID is the server default set in the agentmemory server env for single-role deployments, and AGENTMEMORY_AGENT_ID is a per-client/integration env when multiple clients share one server), surface the precedence rule early (explicitly state “if both AGENTMEMORY_AGENT_ID and AGENT_ID are present in the same process, AGENTMEMORY_AGENT_ID wins”), clarify the “When no agent id is set” sentence to read “When neither AGENT_ID nor AGENTMEMORY_AGENT_ID is set in a process…” and regroup examples into three clear scenarios: Single-role server (AGENT_ID), Multi-client shared server (AGENTMEMORY_AGENT_ID per client), and Per-request overrides (agentId field in API requests).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/config.ts`:
- Around line 284-287: The current selection of AGENTMEMORY_AGENT_ID vs AGENT_ID
uses raw = env["AGENTMEMORY_AGENT_ID"] || env["AGENT_ID"], which treats
whitespace-only AGENTMEMORY_AGENT_ID as present and prevents falling back;
update the logic in the loadAgentScope/config block so you first read
AGENTMEMORY_AGENT_ID, trim it, and if the trimmed value is non-empty use it,
otherwise read and trim AGENT_ID and use that; finally enforce the 128-char
slice and null-return if the resulting agentId is empty. Reference the variables
raw and agentId (and the AGENTMEMORY_AGENT_ID / AGENT_ID env keys) to locate the
change.
---
Nitpick comments:
In `@README.md`:
- Around line 1141-1188: The docs mix server-side vs client-side
config—restructure the Multi-agent memory section to lead with use-case
distinction (explain AGENT_ID is the server default set in the agentmemory
server env for single-role deployments, and AGENTMEMORY_AGENT_ID is a
per-client/integration env when multiple clients share one server), surface the
precedence rule early (explicitly state “if both AGENTMEMORY_AGENT_ID and
AGENT_ID are present in the same process, AGENTMEMORY_AGENT_ID wins”), clarify
the “When no agent id is set” sentence to read “When neither AGENT_ID nor
AGENTMEMORY_AGENT_ID is set in a process…” and regroup examples into three clear
scenarios: Single-role server (AGENT_ID), Multi-client shared server
(AGENTMEMORY_AGENT_ID per client), and Per-request overrides (agentId field in
API requests).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ce334bcb-e586-49c7-b1d4-862cc7c84b35
📒 Files selected for processing (8)
README.mdintegrations/hermes/__init__.pyintegrations/openclaw/plugin.mjssrc/config.tssrc/mcp/server.tstest/agent-id-scope.test.tstest/mcp-agent-id.test.tstest/openclaw-plugin.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- integrations/hermes/init.py
Read AGENTMEMORY_AGENT_ID as the integration-level agent identity, with AGENT_ID kept as the server-level fallback. Forward agentId from Hermes, OpenClaw, and the MCP server in write and search calls so single-server multi-agent deployments can scope memory per integration without modifying individual requests. Add coverage for AGENTMEMORY_AGENT_ID precedence, MCP forwarding, and OpenClaw forwarding. Signed-off-by: Christian de la Cruz <chrisdlc119@outlook.com>
04ad752 to
f250372
Compare
What
All integrations (Hermes, OpenClaw, MCP server) send write and search requests without
agentIdin the request body. This means all memories land withnull agentId— effectively unscoped — even when the server has multi-agent isolation enabled.Why
When multiple agents (e.g. Hermes + Cursor + OpenClaw) share a single agentmemory server, memories from all agents get mixed together because the server has no way to distinguish which agent owns each write. The
AGENT_IDenv var exists as a server-level setting, but integrations never injected their own identity into request bodies.How
src/config.ts:loadAgentScope()readsAGENTMEMORY_AGENT_IDwith fallback toAGENT_ID. This lets integrations define their own identity viaAGENTMEMORY_AGENT_IDin their process env, while the server keeps usingAGENT_IDas its default.integrations/hermes/__init__.py:initialize()capturesagent_idfromkwargs["agent_identity"](the Hermes profile name) withAGENTMEMORY_AGENT_IDenv var as fallback, and passes it to:session/start— tags the sessionremember(memory_save + on_memory_write) — tags saved memoriesobserve(sync_turn) — tags turn observationsintegrations/openclaw/plugin.mjs: ReadsAGENTMEMORY_AGENT_IDfrom process env and forwards it insmart-searchandobservecalls.src/mcp/server.ts: The standalone MCP server readsgetAgentId()and forwards it automatically inmemory_saveandmemory_smart_search. Any MCP client (Cursor, Claude Desktop, Cline, etc.) that setsAGENTMEMORY_AGENT_IDin its MCP configenvgets correct agent tagging without modifying individual tool calls.When no agent identity is available, no
agentIdfield is sent — preserving legacy unscoped behavior.Verification
AGENTMEMORY_AGENT_IDprecedence, MCP forwarding, and OpenClaw forwardingSummary by CodeRabbit
New Features
Documentation
Tests