Skip to content

Agent runtime header lacks session identity, causing misleading self-references #92453

Description

@QQSHI13

Problem

The Runtime: header injected into the system prompt includes agent=main, host=..., model=..., channel=..., etc., but does not include the session key or session ID. This means the agent has no reliable way to know which session it is actually running in.

Current behavior

Runtime: agent=main | host=DESKTOP-70B9P5V | repo=... | os=... | model=... | channel=webchat | capabilities=none | thinking=high

The agent sees agent=main and may infer it is in session agent:main:main, but it does not actually know:

  • Its sessionKey (e.g., agent:main:main, agent:main:subagent:uuid, agent:main:openclaw-weixin:direct:...)
  • Its sessionId (the stable UUID for the session)

This leads to the agent misleadingly claiming it knows its session when it doesn't, or confusing itself about which session it is in when:

  • Receiving heartbeat checks from other sessions
  • Being asked to report its session status
  • Spawning subagents and needing to route messages back
  • Handling cron jobs that target specific sessions

Impact

  1. Self-identity confusion: The agent says things like "I am in agent:main:main" when it only knows agent=main — the rest is inference/guesswork.
  2. Heartbeat debugging: When a heartbeat arrives from another session, the agent cannot accurately identify its own session vs. the source session.
  3. Subagent orchestration: The agent cannot tell a subagent "report back to THIS session" because it doesn't know its own session key.
  4. Session routing: When asked to send a message to a specific session, the agent may guess wrong about its own session key.

Proposed solution

Add sessionKey and sessionId to the RuntimeInfoInput type and include them in the Runtime: header, e.g.:

Runtime: agent=main | session=agent:main:main | sessionId=23ae7fce-3c27-4a51-b58e-d800d8ca091f | host=... | os=... | model=... | channel=... | capabilities=... | thinking=...

Files involved

  • src/agents/system-prompt-params.tsRuntimeInfoInput type and buildSystemPromptParams()
  • src/agents/system-prompt.tsbuildRuntimeLine() function
  • src/agents/embedded-agent-runner/run/attempt.ts — where runtimeInfo is constructed and passed

This is a small, additive change that would eliminate an entire class of session-identity confusion without affecting any other functionality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions