Skip to content

refactor(protocol): type sub-agent completion as MessageSource::AgentResult#196

Merged
yishuiliunian merged 1 commit into
mainfrom
refactor/agent-result-typed-source
Jun 11, 2026
Merged

refactor(protocol): type sub-agent completion as MessageSource::AgentResult#196
yishuiliunian merged 1 commit into
mainfrom
refactor/agent-result-typed-source

Conversation

@yishuiliunian

Copy link
Copy Markdown
Contributor

Summary

  • Promote sub-agent completion results from an in-body <agent-result name=...> string to a typed MessageSource::AgentResult { child } variant, so the semantic lives in the type system rather than being string-parsed/string-rendered by each consumer.
  • The envelope body stays raw; the <agent-result> wrapper is rebuilt only at LLM projection time. Cross-hub completion detection now matches the typed source instead of byte-scanning the content.
  • Sweeps two adjacent debts: SSOT the turn-trigger LLM-text prefixes into trigger_llm_text (shared by wire projection + Anthropic builder), and fix DegenerationDetector to reuse MessageSource::is_task_boundary (its hand-rolled list silently dropped peer-agent envelopes its comment claimed to clear).

Changes

  • loopal-protocol: new MessageSource::AgentResult { child } variant + label/is_task_boundary/prepend_hub/prepend_hub_if_local arms.
  • loopal-turn: new TurnTrigger::AgentResult variant.
  • loopal-agent-hub: producers (completion.rs/finish.rs) emit raw body + typed source; uplink.rs detects completion by source type (removed extract_agent_result_name byte-parser).
  • loopal-provider-api: extract trigger_llm_text SSOT (prefix.rs); refactor trigger.rs into text + origin projection.
  • loopal-provider: Anthropic trigger_user collapses onto the shared trigger_llm_text.
  • loopal-runtime: turn_trigger_map maps AgentResult source (bare child name); degeneration_detector reuses is_task_boundary.
  • loopal-tui: render_inbox_origin shows a ✅ result from <child> badge instead of raw XML tags.
  • Tests updated/added across protocol, provider-api, runtime, tui, meta-hub.

Notes

  • The <agent-result name=...> marker uses the bare child name even for cross-hub completions (hub path stripped) to match the prior contract.
  • Agent completions deliberately drop the redundant [from: <child>] prefix — the marker already identifies the source.
  • ACP _loopal/inbox.enqueued.source now emits the new AgentResult wire variant (serde pass-through); IDE clients should handle it.

Test plan

  • CI passes (bazel test //..., clippy, rustfmt)

…Result

Sub-agent completion results were encoded as a `<agent-result name=...>`
string baked into the envelope body. That buried a real domain concept
(completion vs. ordinary peer-agent message) in text, forcing every
consumer to deal with it differently: the uplink string-parsed the marker
as a control signal, the TUI showed the raw XML tags to users, and ACP had
no mapping.

Promote it to a typed `MessageSource::AgentResult { child }` variant. The
envelope body stays raw; the `<agent-result>` wrapper is rebuilt only at
LLM projection time, so the model sees the same marker while observers
render structurally. Cross-hub completion detection now matches the typed
source instead of parsing bytes.

Also clears two adjacent debts surfaced while doing this:
- SSOT the turn-trigger LLM-text prefixes (`[from:]`/`[scheduled]`/
  `<agent-result>`) into `trigger_llm_text`, shared by the wire projection
  and the Anthropic request builder (previously duplicated, drift-prone).
- DegenerationDetector reused a hand-rolled boundary list that dropped
  peer-agent envelopes its own comment claimed to clear; switch it to the
  `MessageSource::is_task_boundary` SSOT.

Notes:
- The `<agent-result name=...>` marker uses the bare child name even for
  cross-hub completions (hub path stripped) to match the prior contract.
- Agent completions deliberately drop the redundant `[from: <child>]`
  prefix — the marker already identifies the source.
@yishuiliunian yishuiliunian merged commit c6c2239 into main Jun 11, 2026
3 of 4 checks passed
@yishuiliunian yishuiliunian deleted the refactor/agent-result-typed-source branch June 11, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant