feat(runs): agent-to-agent messages — tagged sender, hold, send --children / --parent #51

Open
gabrielvidal wants to merge 1 commits from agent-messaging into main
pull from: agent-messaging
Owner

Summary

A run can already start conversations on any harness and model (ai-agent new --model …) and continue them (ai-agent send). This makes messages between agents first-class: a turn another conversation's agent sent is labelled as that agent's instead of the user's, no longer interrupts a live pi / opencode / agy run, can go to every running child at once, and can go from a child up to its parent mid-run. Trigger: a Gemini (agy) run updating its Opus 5.5 children.

Key changes

  • backend/runs/agentmsg.py (new): who the sender is to the target (parent / child / peer), the app tag and framing line for each, the hold store (meta.heldSends) and sweep_held, which resumes a conversation on its held messages once its turn has ended.
  • backend/runs/routes.py: /api/resume with a parent (the CLI's own session) tags the turn, and holds it when the owner's target has a live run with no inbox; a held send does not re-arm the report (the delivery does).
  • backend/runs/sidecar_client.py: the run-exit watcher runs sweep_held before sweep_reports.
  • backend/runs/children.py: no report goes out while a message is held for the child, or for the parent it would resume.
  • cli/ai_agent.py: send --children PROMPT, send --parent PROMPT, - reads the message from stdin, a held line in the output, and wait sits through a card that still has held messages.
  • frontend Conversation.tsx: the Workflow icon for the parent-agent and agent app authors, as for subagent.
  • Docs: CLAUDE.md → "Agent-to-agent messages"; the shipped cli/skills/ai-agent/SKILL.md.

Key decisions

  • Tagged as an app turn, not a new role. Reuses the <ai-agent-from … role="app"/> path the child reports already take, so the inbox prefix, every reader and the viewer row work unchanged. Before, a parent agent's update reached a live Claude child as "this IS your user's own message".
  • Hold only for agent sends. Gabriel's composer keeps its stop + resume into a non-Claude run; only a send that names a calling session is held. --now keeps the old behaviour.
  • Hold in the hub, not per-harness injection. Real mid-turn delivery into pi / opencode / agy needs a way in per harness and was left out (form messaging-a-child-conversation-on-another_x62jtl).
  • A held message replaces the pending report. The child's first answer is not reported; the one after the held message is. Otherwise the parent would get an answer its own update had already made stale.
  • Guests: their runs' sends are tagged too (forged tags defused), but never held — the held delivery resumes a guest's session on claude only.
  • --model / --effort do not ride a held message.

Changelog

  • Added: ai-agent send --children "…" sends one message to every running child conversation.
  • Added: ai-agent send --parent "…" lets a child conversation send its parent a note or a question while it works.
  • Changed: a message one conversation's agent sends another is shown and read as that agent's (Parent agent, Subagent, Another conversation), no longer as your own.
  • Changed: a message an agent sends to a running pi, opencode or agy conversation waits for its turn to end instead of interrupting it (--now interrupts).

Test notes

  • scripts/test.py backend — 2302 passed, 1 failed: test_labsync.py::test_hash_follows_content_and_mode, which also fails 2 runs out of 3 on an untouched main (flaky, unrelated).
  • scripts/test.py cli types — 116 passed, tsc clean. New: backend/test_agentmsg.py (6), four CLI tests.
  • Not run live: no end-to-end send between real runs (it needs the deploy). After merge: from an agy run, ai-agent new --test --model haiku, send to it, check the tag in the child's thread; same with a pi child for the hold.
  • No screenshot: the only visible change is the icon of the app row.
  • After deploy, the homelab's own .claude/skills/ai-agent/SKILL.md should gain the two flags (not in this PR: another repo).

🤖 Generated with Claude Code

## Summary A run can already start conversations on any harness and model (`ai-agent new --model …`) and continue them (`ai-agent send`). This makes messages *between* agents first-class: a turn another conversation's agent sent is labelled as that agent's instead of the user's, no longer interrupts a live pi / opencode / agy run, can go to every running child at once, and can go from a child up to its parent mid-run. Trigger: a Gemini (agy) run updating its Opus 5.5 children. ## Key changes - `backend/runs/agentmsg.py` (new): who the sender is to the target (parent / child / peer), the app tag and framing line for each, the hold store (`meta.heldSends`) and `sweep_held`, which resumes a conversation on its held messages once its turn has ended. - `backend/runs/routes.py`: `/api/resume` with a `parent` (the CLI's own session) tags the turn, and holds it when the owner's target has a live run with no inbox; a held send does not re-arm the report (the delivery does). - `backend/runs/sidecar_client.py`: the run-exit watcher runs `sweep_held` before `sweep_reports`. - `backend/runs/children.py`: no report goes out while a message is held for the child, or for the parent it would resume. - `cli/ai_agent.py`: `send --children PROMPT`, `send --parent PROMPT`, `-` reads the message from stdin, a `held` line in the output, and `wait` sits through a card that still has held messages. - `frontend` `Conversation.tsx`: the Workflow icon for the `parent-agent` and `agent` app authors, as for `subagent`. - Docs: `CLAUDE.md` → "Agent-to-agent messages"; the shipped `cli/skills/ai-agent/SKILL.md`. ## Key decisions - **Tagged as an app turn, not a new role.** Reuses the `<ai-agent-from … role="app"/>` path the child reports already take, so the inbox prefix, every reader and the viewer row work unchanged. Before, a parent agent's update reached a live Claude child as "this IS your user's own message". - **Hold only for agent sends.** Gabriel's composer keeps its stop + resume into a non-Claude run; only a send that names a calling session is held. `--now` keeps the old behaviour. - **Hold in the hub, not per-harness injection.** Real mid-turn delivery into pi / opencode / agy needs a way in per harness and was left out (form `messaging-a-child-conversation-on-another_x62jtl`). - **A held message replaces the pending report.** The child's first answer is not reported; the one after the held message is. Otherwise the parent would get an answer its own update had already made stale. - **Guests:** their runs' sends are tagged too (forged tags defused), but never held — the held delivery resumes a guest's session on claude only. - `--model` / `--effort` do not ride a held message. ## Changelog - Added: `ai-agent send --children "…"` sends one message to every running child conversation. - Added: `ai-agent send --parent "…"` lets a child conversation send its parent a note or a question while it works. - Changed: a message one conversation's agent sends another is shown and read as that agent's (Parent agent, Subagent, Another conversation), no longer as your own. - Changed: a message an agent sends to a running pi, opencode or agy conversation waits for its turn to end instead of interrupting it (`--now` interrupts). ## Test notes - `scripts/test.py backend` — 2302 passed, 1 failed: `test_labsync.py::test_hash_follows_content_and_mode`, which also fails 2 runs out of 3 on an untouched `main` (flaky, unrelated). - `scripts/test.py cli types` — 116 passed, tsc clean. New: `backend/test_agentmsg.py` (6), four CLI tests. - **Not run live**: no end-to-end send between real runs (it needs the deploy). After merge: from an agy run, `ai-agent new --test --model haiku`, `send` to it, check the tag in the child's thread; same with a pi child for the hold. - No screenshot: the only visible change is the icon of the app row. - After deploy, the homelab's own `.claude/skills/ai-agent/SKILL.md` should gain the two flags (not in this PR: another repo). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gabrielvidal self-assigned this 2026-11-30 15:40:58 +01:00
gabrielvidal added 1 commit 2026-11-30 15:40:58 +01:00
This pull request has changes conflicting with the target branch.
  • cli/ai_agent.py
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin agent-messaging:agent-messaging
git checkout agent-messaging
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: gabrielvidal/ai-agent#51