hermes - 💡(How to fix) Fix Feature Request: Add delegated_role field to delegated sessions

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Fix Action

Fix / Workaround

Current Workaround

  1. Parse the first user message for role names — Fragile; the task description may not mention the role.
  2. Use a separate attribution log file — Our current workaround. Works but isn't queryable, isn't durable across DB operations, and requires manual bookkeeping.
  3. Store it in model_config JSON — The model_config column already exists but contains provider/model info, not role/persona metadata. Overloading it would make parsing harder.
  • Multi-profile Hermes setups commonly designate one profile as a builder agent and another as a research agent, each needing its own token attribution for usage reporting and cost tracking.
  • The sessions table already has parent_session_id and model_config — this is a natural extension of the existing delegation metadata.
  • Related: delegate_task already resolves delegation.model / delegation.provider per-profile. The delegated_role would carry the profile name alongside those resolved values.
  • Current workaround for hiding delegated sessions is a heuristic in list_sessions_rich() (hermes_state.py:1626-1635): child sessions with parent_session_id are excluded from default views when the parent wasn't branched. A delegated_role column would make this deterministic rather than heuristic.

Code Example

ALTER TABLE sessions ADD COLUMN delegated_role TEXT;

---

child._delegate_role = effective_role  # "leaf" or "orchestrator"
RAW_BUFFERClick to expand / collapse

Feature Request: Add delegated_role field to delegated sessions

Problem

When delegate_task spawns a subagent, the child session inherits the parent's session metadata but has no field recording which role or persona it was delegated as. The child session gets a parent_session_id pointing back to the parent, and it gets whatever model/provider was resolved for delegation, but there's no way to answer "was this session spawned as the builder agent or the research agent?" from the session record alone.

This makes attribution impossible in:

  • Usage reporting — All delegated sessions roll up under the parent profile's token counts. A daily usage report can't split "the main agent used X tokens" from "the builder agent used Y tokens" from "the research agent used Z tokens" without fragile heuristics (e.g., parsing the first user message for role names).
  • Session browsinghermes sessions list shows delegated sessions without any role metadata, making it hard to filter by role — "show me all builder sessions" or "show me all research sessions."
  • Billing attribution — When different profiles map to different cost centers or budgets, there's no reliable way to attribute spend.

Current Workaround

Appending a manual attribution log after each delegate_task call, mapping child_session_id → role_name. This works but:

  • Requires manual bookkeeping (or a wrapper skill that's fragile)
  • Is not queryable from the session database
  • Breaks if the user forgets to log

Proposed Solution

Add a delegated_role text column to the sessions table, and populate it at child session creation time in _build_child_agent().

Schema change

ALTER TABLE sessions ADD COLUMN delegated_role TEXT;

Population

In tools/delegate_tool.py, when _build_child_agent() creates the child AIAgent:

  • If the parent delegate call came from a named profile (e.g., my-builder), set delegated_role to that profile name.
  • If the parent used the role kwarg on delegate_task (e.g., "leaf" vs "orchestrator"), store that too — or make it a separate field like delegate_role.

The parent_session_id already links the child to the parent. The delegated_role field would link the child to the role/persona it was spawned as, without requiring the parent to manually log it.

API exposure

  • hermes sessions list / hermes sessions browse could show delegated_role in the table.
  • hermes insights --days N could group by delegated_role for cost attribution.
  • The delegate_task summary could include delegated_role so the parent agent can report it.

Backward compatibility

  • Existing sessions get NULL for delegated_role — no migration needed.
  • The column is informational only — no code path depends on it for correctness.

Alternatives Considered

  1. Parse the first user message for role names — Fragile; the task description may not mention the role.
  2. Use a separate attribution log file — Our current workaround. Works but isn't queryable, isn't durable across DB operations, and requires manual bookkeeping.
  3. Store it in model_config JSON — The model_config column already exists but contains provider/model info, not role/persona metadata. Overloading it would make parsing harder.

Related Issues & PRs

IDTitleStatusRelevance
#39372"Background/integration agent runs should not pollute user-visible session lists"OpenSame problem space — delegated/cron sessions lack metadata. Proposes session_source field. delegated_role is complementary.
#39506 (PR)"[codex] Hide internal agent sessions by default"DraftAdds visibility column (user/internal/hidden) — orthogonal approach (hiding vs attributing). Both fields are useful; neither subsumes the other.
#24321"AIAgent._ensure_db_session() drops user_id on session-row creation; bg/cron/delegate sessions land orphan in state.db"OpenDelegate sessions are missing user_id. delegated_role would pair naturally with a fix for this.
#38378"feat: optional auto-cleanup of cron job sessions from session DB"OpenCron session pollution — 1,717 cron sessions in 6 weeks. Attribution helps decide what to keep vs clean up.

Existing Code That Already Does Half the Job

delegate_tool.py:1146 already sets a runtime-only _delegate_role attribute on child AIAgent instances:

child._delegate_role = effective_role  # "leaf" or "orchestrator"

This is used in stop hooks and diagnostics but never persisted to the sessions table. The proposed feature would extend this: persist a richer value (role name or profile name) at session-creation time alongside the existing parent_session_id.

Additional Context

  • Multi-profile Hermes setups commonly designate one profile as a builder agent and another as a research agent, each needing its own token attribution for usage reporting and cost tracking.
  • The sessions table already has parent_session_id and model_config — this is a natural extension of the existing delegation metadata.
  • Related: delegate_task already resolves delegation.model / delegation.provider per-profile. The delegated_role would carry the profile name alongside those resolved values.
  • Current workaround for hiding delegated sessions is a heuristic in list_sessions_rich() (hermes_state.py:1626-1635): child sessions with parent_session_id are excluded from default views when the parent wasn't branched. A delegated_role column would make this deterministic rather than heuristic.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING