Skip to content

Commit 6c920d2

Browse files
wesbillmanBrainPinky
authored
fix(buzz-acp): human-aware reply anchoring to keep threads flat (#1281)
Signed-off-by: Wes <[email protected]> Co-authored-by: Brain <21994759fc7a6fa6b965551d35cfd7897d262f2495467f2d78694ddcfa6a5c7e@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co>
1 parent c996be3 commit 6c920d2

5 files changed

Lines changed: 642 additions & 39 deletions

File tree

‎crates/buzz-acp/src/base_prompt.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ Run `buzz --help` or `buzz <group> --help` for full usage.
3434

3535
### Threading
3636

37-
- **To a human** (updates, questions, deliverables): Use `--reply-to <thread-root-id>` (from your `[Context]` block) and `@mention` the human. Keeps messages at layer 1 where humans read.
38-
- **To another agent** (dispatching, collaborating): Thread however you want.
39-
- **When in doubt**, reply to thread root.
40-
- **Thread scope:** Respond in the thread where you were tagged. New top-level message from someone = new thread — respond there, not the old one.
41-
- **New topic → new top-level message.** Don't graft unrelated work onto an existing thread.
37+
Use the reply destination supplied in the `[Context]` block for ordinary replies in this turn. Do not reuse a remembered thread id, an older event id from prior work, or a stale conversation root.
38+
39+
For human-facing work, keep the conversation flat and easy to read. The app/harness will choose the correct reply destination: the root of the triggering thread when the turn is already threaded, or the triggering top-level event when the human started a new thread.
40+
41+
For agent-to-agent coordination with no human in the loop, deeper nesting is allowed when it helps preserve task structure. Do not flatten agent-only subthreads just because they are inside a thread.
42+
43+
When in doubt, prefer the reply destination explicitly supplied in `[Context]`. If you intentionally choose a different destination, explain why briefly in the message.
4244

4345
### General
4446

‎crates/buzz-acp/src/pool.rs‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,24 @@ fn collect_prompt_pubkeys(
16271627
pubkeys
16281628
}
16291629

1630+
/// Detect whether a kind:0 profile event belongs to an owned agent.
1631+
///
1632+
/// Agents carry a NIP-OA `["auth", owner_pk, conditions, sig]` tag in their
1633+
/// profile; humans do not. This checks for the tag's presence/shape only — a
1634+
/// cheap routing heuristic for reply anchoring, not a verified security gate
1635+
/// (the signing path in `lib.rs::check_sibling_via_profile` does full
1636+
/// verification where it matters).
1637+
fn profile_event_is_agent(ev: &serde_json::Value) -> bool {
1638+
ev.get("tags")
1639+
.and_then(|t| t.as_array())
1640+
.is_some_and(|tags| {
1641+
tags.iter().any(|tag| {
1642+
tag.as_array()
1643+
.is_some_and(|parts| parts.len() == 4 && parts[0].as_str() == Some("auth"))
1644+
})
1645+
})
1646+
}
1647+
16301648
/// Parse kind:0 profile events into a `PromptProfileLookup`.
16311649
///
16321650
/// Each kind:0 event has `pubkey` and JSON `content` with optional fields:
@@ -1649,11 +1667,13 @@ fn parse_kind0_profile_lookup(json: serde_json::Value) -> Option<PromptProfileLo
16491667
.get("nip05")
16501668
.and_then(|v| v.as_str())
16511669
.map(str::to_string);
1670+
let is_agent = profile_event_is_agent(ev);
16521671
lookup.insert(
16531672
pk.to_ascii_lowercase(),
16541673
PromptProfile {
16551674
display_name,
16561675
nip05_handle,
1676+
is_agent,
16571677
},
16581678
);
16591679
}
@@ -2784,10 +2804,33 @@ mod tests {
27842804
Some(&PromptProfile {
27852805
display_name: Some("Wes".into()),
27862806
nip05_handle: Some("[email protected]".into()),
2807+
is_agent: false,
27872808
})
27882809
);
27892810
}
27902811

2812+
#[test]
2813+
fn test_profile_event_is_agent_detects_nip_oa_auth_tag() {
2814+
// Agent profile carries a 4-element NIP-OA ["auth", owner, cond, sig] tag.
2815+
let agent_ev = json!({
2816+
"pubkey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
2817+
"tags": [["auth", "owner_pk", "conditions", "sig"]],
2818+
});
2819+
assert!(profile_event_is_agent(&agent_ev));
2820+
2821+
// Human profile: no auth tag.
2822+
let human_ev = json!({ "pubkey": "bbbb", "tags": [["t", "topic"]] });
2823+
assert!(!profile_event_is_agent(&human_ev));
2824+
2825+
// Empty / missing tags → not an agent.
2826+
assert!(!profile_event_is_agent(&json!({ "tags": [] })));
2827+
assert!(!profile_event_is_agent(&json!({})));
2828+
2829+
// Malformed auth tag (wrong arity) → not treated as an agent.
2830+
let malformed = json!({ "tags": [["auth", "owner_pk"]] });
2831+
assert!(!profile_event_is_agent(&malformed));
2832+
}
2833+
27912834
#[test]
27922835
fn test_parse_kind0_profile_lookup_returns_none_for_empty() {
27932836
assert!(parse_kind0_profile_lookup(json!([])).is_none());

0 commit comments

Comments
 (0)