#7516: feat(sessions): Auto-inject From:/To: identity headers in agent-to-agent messages
agents
Cluster:
UI Enhancements and Fixes
## 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
#22977: fix(ui): resolve agent names from config in session dropdown
by NikhilGaddam · 2026-02-21
78.7%
#15792: fix: pass agentId to resolveSessionFilePath in additional call sites
by MisterGuy420 · 2026-02-13
77.3%
#9051: fix(sessions): respect dmScope config in CLI agent commands
by benleavett · 2026-02-04
76.4%
#20072: feat(sessions_spawn): add sessionKey param to reuse sub-agent sessions
by Be1Human · 2026-02-18
76.0%
#6840: Fix assistant identity default agent for global sessions
by JorgeAlan · 2026-02-02
75.8%
#11497: feat(exec): inject agent identity env vars for subagents
by NOVA-Openclaw · 2026-02-07
75.7%
#13246: feat: inject agent/session context as environment variables in exec...
by LePetitPince · 2026-02-10
75.6%
#9726: feat: add identityDir config for separate identity file location
by rickburn · 2026-02-05
75.4%
#15732: [AI-assisted] feat: emit agent:response internal hook after replies
by zontasticality · 2026-02-13
75.4%
#6850: fix: support direct channel:account:peer format in session key extr...
by toboto · 2026-02-02
75.3%