← Back to PRs

#7516: feat(sessions): Auto-inject From:/To: identity headers in agent-to-agent messages

by RusDyn open 2026-02-02 22:39 View on GitHub →
agents
## Summary When agents communicate via `sessions_send`, recipient agents currently see anonymous messages with no indication of who sent them. This PR automatically injects `From:` and `To:` headers using agent display names from config. **Before:** Agent-to-agent message context: Agent 1 (requester) session: agent:landing. Agent 1 (requester) channel: #landing-builder. Agent 2 (target) session: agent:openclaw. The Stripe webhook is deployed! Here's what you need to configure... **After:** Agent-to-agent message context: From: Tessa (landing), session: agent:landing. From channel: #landing-builder. To: Leo (openclaw), session: agent:openclaw. The Stripe webhook is deployed! Here's what you need to configure... ## Motivation In multi-agent setups, agents frequently message each other via `sessions_send`. Without identity headers, recipients can't tell if a message came from the supervisor, a peer agent, or a subagent — leading to confusion about who said what. This came up in my 9-agent team where an agent (Tessa) contacted another agent (Leo), but Leo couldn't identify the sender and assumed it was the supervisor (Adam). Related: #15778 (expose subagent ID) ## Changes - **sessions-send-helpers.ts**: Added `buildAgentLabel()` helper and updated `buildAgentToAgentMessageContext()` to include From:/To: labels - **sessions-send-tool.ts**: Pass config to enable name resolution ## Testing - [x] Tested locally with multi-agent OpenClaw setup (9 agents) - [x] Verified headers appear correctly in recipient's message context - [x] Confirmed graceful fallback when display name not configured (uses agentId) ## AI Disclosure 🤖 - AI-assisted: Yes (Claude helped with code review and this PR description) - Testing level: Fully tested in production multi-agent environment - I understand what the code does: Yes, I'm the one who identified the problem and designed the solution <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR enhances `sessions_send` agent-to-agent messaging by auto-injecting identity context into the recipient system prompt. It derives requester/target agent IDs from session keys, resolves optional display names from config, and formats the injected context as `From:` / `To:` plus channel/session information. The send tool now passes the loaded config into the helper so labels can be resolved consistently. <h3>Confidence Score: 4/5</h3> - This PR is generally safe to merge; changes are localized to message-context formatting and config plumbing. - Reviewed both touched files and the only notable concern is over-aggressive sanitization of configured display names; behavior otherwise appears consistent with existing session-key resolution and tool flow. - src/agents/tools/sessions-send-helpers.ts <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs