diff --git a/crates/dim-agent-capabilities/src/narrative.rs b/crates/dim-agent-capabilities/src/narrative.rs index 92ed8f2c9..27d2712ce 100644 --- a/crates/dim-agent-capabilities/src/narrative.rs +++ b/crates/dim-agent-capabilities/src/narrative.rs @@ -31,10 +31,37 @@ const PAGE_CHARACTERS: usize = 8_000; /// Characters a variable part of a line keeps, its `…` included (§3.4). const PART: usize = 120; /// Longest `about` a query accepts (§5.2). -pub const ABOUT: usize = 200; +const ABOUT: usize = 200; /// Events one read asks for. The answer, not this page, ends the read. const PAGE_EVENTS: usize = 128; +/// The schema properties of a [`Query`], the same for every reader (§5.2). +pub fn query_properties() -> JsonObject { + let Value::Object(properties) = json!({ + "about": { + "type": "string", + "minLength": 1, + "maxLength": ABOUT, + "description": "Words to look for; all must appear, in any order, ignoring case." + }, + "tool": { + "type": "string", + "minLength": 1, + "description": "Only calls to this tool." + }, + "before": {"type": "string", "description": "A line's id; show what came before it."}, + "open": {"type": "string", "description": "A line's id; show it in full."}, + "offset": { + "type": "integer", + "minimum": 0, + "description": "With open: continue from here, a line of a turn or a character of one thing." + } + }) else { + unreachable!("an object literal") + }; + properties +} + /// The grammatical person the account is told in (§3.8). #[derive(Clone, Copy, PartialEq, Eq)] pub enum Person { diff --git a/crates/dim-agent-capabilities/src/recall.rs b/crates/dim-agent-capabilities/src/recall.rs index 16f449f7f..dfa4e4649 100644 --- a/crates/dim-agent-capabilities/src/recall.rs +++ b/crates/dim-agent-capabilities/src/recall.rs @@ -5,7 +5,7 @@ //! `docs/architecture/rust-agent/plugins/Recall.md`. use crate::{ host::{HostError, HostFuture, ToolExecutionContext}, - narrative::{self, ABOUT, Person, Query}, + narrative::{self, Person, Query}, timeline_tree::TreeCommands, tool_registry::{ToolConcurrency, ToolContribution, ToolHandler, ToolRegistry, definition}, }; @@ -37,32 +37,10 @@ pub fn install(builder: &mut AgentBuilder) { fn recall_definition() -> ToolDefinition { let mut definition = definition( RECALL_TOOL, - "Recall what happened earlier in this conversation, including what a compaction summarized: what the user said, what you did and what came back. With no arguments it lists past turns; open a turn or anything in it by its id, or search with about. A shortened input that ends in [input ] is read in full by opening that id.", + "Recall what happened earlier in this conversation, including what a compaction summarized: what the user said, what you did and what came back. With no arguments it lists past turns; open any line by its id, or search with about. A shortened input that ends in [input ] is read in full by opening that id.", json!({ "type": "object", - "properties": { - "about": { - "type": "string", - "minLength": 1, - "maxLength": ABOUT, - "description": "Words to look for; all must appear, in any order, ignoring case." - }, - "tool": { - "type": "string", - "minLength": 1, - "description": "Only calls to this tool." - }, - "before": {"type": "string", "description": "An id; show what came before it."}, - "open": { - "type": "string", - "description": "An id; show that turn, or that thing in full." - }, - "offset": { - "type": "integer", - "minimum": 0, - "description": "With open: continue from here, a line of a turn or a character of one thing." - } - }, + "properties": narrative::query_properties(), "additionalProperties": false }), ); diff --git a/crates/dim-app-server/src/collaboration.rs b/crates/dim-app-server/src/collaboration.rs index e0e94ace7..2ee38dbd6 100644 --- a/crates/dim-app-server/src/collaboration.rs +++ b/crates/dim-app-server/src/collaboration.rs @@ -3075,9 +3075,8 @@ const LEADER_DESCRIPTION_HEAD: &str = "Work with other agents as a team you lead on it now, waking it when idle. Mode \"append\" adds context the receiver sees in its next step without interrupting it, and waits while it is idle. A message starts no task and returns no result; give new work with request. -- read: a briefing of a team member's activity, latest turns first; open a turn or - anything in it by its id, or search with about. list: show your team and the agents - you can use. inspect: show one agent's full profile (instructions, tools, model)."; +- read: a team member's activity, latest turns first; open any line by its id, or + search with about. list: show your team and the agents you can use. inspect: show one agent's full profile (instructions, tools, model)."; /// The `models` bullet, between [`LEADER_DESCRIPTION_HEAD`] and /// [`LEADER_DESCRIPTION_TAIL`]: only a deployment that provides the selectable /// read offers the action. @@ -3091,8 +3090,8 @@ const MEMBER_DESCRIPTION: &str = "You are a member of a team. You cannot delegat - message: send information to your leader or another member. Default mode \"steer\" has the receiver act on it now, waking it when idle. Mode \"append\" adds context the receiver sees in its next step without interrupting it, and waits while it is idle. -- read: a briefing of a team member's activity, latest turns first; open a turn or - anything in it by its id, or search with about. list: show your team. +- read: a team member's activity, latest turns first; open any line by its id, or + search with about. list: show your team. When you finish a task, your last reply is the result the leader receives; do not send it as a message."; @@ -3107,14 +3106,11 @@ fn agent_definition( "sessionId": {"type": "string"}, "content": {"type": "string"}, "mode": {"type": "string", "enum": ["append", "steer"]}, - "about": {"type": "string", "minLength": 1, "maxLength": narrative::ABOUT, - "description": "Words to look for; all must appear, in any order, ignoring case."}, - "tool": {"type": "string", "minLength": 1, "description": "Only calls to this tool."}, - "before": {"type": "string", "description": "An id; show what came before it."}, - "open": {"type": "string", "description": "An id; show that turn, or that thing in full."}, - "offset": {"type": "integer", "minimum": 0, - "description": "With open: continue from here, a line of a turn or a character of one thing."}, }); + properties + .as_object_mut() + .expect("an object literal") + .extend(narrative::query_properties()); let (actions, description) = match role { CollaborationRole::Leader => { properties["resultId"] = json!({"type": "string"}); diff --git a/crates/dim-app-server/tests/transport_flow/collaboration.rs b/crates/dim-app-server/tests/transport_flow/collaboration.rs index f9cd58c03..b89c11d6e 100644 --- a/crates/dim-app-server/tests/transport_flow/collaboration.rs +++ b/crates/dim-app-server/tests/transport_flow/collaboration.rs @@ -1984,6 +1984,21 @@ async fn leader_delegates_and_team_members_communicate() { participants[].agentId for a team member. A name such as \"default\" is not an id." ) ); + for (field, declared) in dim_agent_capabilities::narrative::query_properties() { + assert_eq!( + schema["properties"][&field], declared, + "read declares Recall's query: {field}" + ); + } + let member_guidance = &member_tools + .iter() + .find(|t| t.name == "agent") + .unwrap() + .description; + assert!( + member_guidance.contains("open any line by its id"), + "{member_guidance}" + ); let leader_tools = events(&lead_session) .await .iter() @@ -1999,7 +2014,8 @@ async fn leader_delegates_and_team_members_communicate() { .description; assert!( guidance.contains("agentId is copied exactly from list's agents[].agentId") - && guidance.contains("is not an agentId"), + && guidance.contains("is not an agentId") + && guidance.contains("open any line by its id"), "{guidance}" ); let schema = serde_json::to_value( diff --git a/crates/dim-app-server/tests/transport_flow/recall.rs b/crates/dim-app-server/tests/transport_flow/recall.rs index 9a9306a55..94250d886 100644 --- a/crates/dim-app-server/tests/transport_flow/recall.rs +++ b/crates/dim-app-server/tests/transport_flow/recall.rs @@ -23,6 +23,19 @@ impl Provider { .filter_map(|tool| tool["function"]["name"].as_str().map(str::to_owned)) .collect() } + + /// The `recall` declaration the model last saw. + fn recall(&self) -> Value { + let requests = self.requests.lock().unwrap(); + let body = requests.last().expect("the model was called"); + body["tools"] + .as_array() + .expect("a declared tool table") + .iter() + .find(|tool| tool["function"]["name"] == "recall") + .map(|tool| tool["function"].clone()) + .expect("recall is declared") + } } async fn completion(State(provider): State>, Json(body): Json) -> String { @@ -142,6 +155,21 @@ async fn both_profiles_declare_recall() { let tools = provider.tools(); assert!(tools.iter().any(|tool| tool == "recall"), "{tools:?}"); assert!(tools.iter().any(|tool| tool == "wait"), "{tools:?}"); + let recall = provider.recall(); + assert!( + recall["description"] + .as_str() + .unwrap() + .contains("open any line by its id"), + "{recall}" + ); + for (field, declared) in dim_agent_capabilities::narrative::query_properties() { + assert_eq!( + recall["parameters"]["properties"][&field]["description"], + declared["description"], + "recall declares the shared query: {field}" + ); + } assert_ok(&client.rpc("daemon.shutdown", json!({"force":false})).await); assert!(product.child.wait().await.unwrap().success()); diff --git a/docs/design/plugins/Recall.md b/docs/design/plugins/Recall.md index 94a96b4c1..eafd274c9 100644 --- a/docs/design/plugins/Recall.md +++ b/docs/design/plugins/Recall.md @@ -383,6 +383,10 @@ nothing; it only drops the address to the reader: Without a turn of its own, every turn without a `turn/end` on the read line is `in progress`. +Every reader declares the query of §5.2 with the same schema properties, which the component +owns (`narrative::query_properties`), so a reader's parameters cannot drift from what the +projection accepts. + A handle belongs to the line it was shown on (§4). A reader whose line can change between calls, as a member's current line can, may hold a handle the new line does not have; that handle is refused as any unknown id is (§6), and the refusal tells the reader to read again without `open` @@ -417,7 +421,7 @@ Registered with the Session's `toolRegistry` under the name `recall` | `name` | `recall` | | `risk` | `session` | | `source` | `extension` | -| `description` | "Recall what happened earlier in this conversation, including what a compaction summarized: what the user said, what you did and what came back. With no arguments it lists past turns; open a turn or anything in it by its id, or search with about. A shortened input that ends in [input ] is read in full by opening that id." | +| `description` | "Recall what happened earlier in this conversation, including what a compaction summarized: what the user said, what you did and what came back. With no arguments it lists past turns; open any line by its id, or search with about. A shortened input that ends in [input ] is read in full by opening that id." | The declaration is the only prompt. The summary, the replacement and the system prompt do not mention the tool (§7). @@ -432,8 +436,8 @@ mention the tool (§7). "description": "Words to look for; all must appear, in any order, ignoring case."}, "tool": {"type": "string", "minLength": 1, "description": "Only calls to this tool."}, - "before": {"type": "string", "description": "An id; show what came before it."}, - "open": {"type": "string", "description": "An id; show that turn, or that thing in full."}, + "before": {"type": "string", "description": "A line's id; show what came before it."}, + "open": {"type": "string", "description": "A line's id; show it in full."}, "offset": {"type": "integer", "minimum": 0, "description": "With open: continue from here, a line of a turn or a character of one thing."} }, diff --git a/docs/zh/design/plugins/Recall.md b/docs/zh/design/plugins/Recall.md index 565273e53..35c40cd9a 100644 --- a/docs/zh/design/plugins/Recall.md +++ b/docs/zh/design/plugins/Recall.md @@ -176,6 +176,8 @@ Recall 按块文本的开头标签与属性,以及 `InputBlock::Raw` 的 `key` 没有自己的那一轮时,所读的线上每个没有 `turn/end` 的轮次都是 `in progress`。 +每个读者都用同样的 schema 属性声明 §5.2 的查询,这些属性由组件持有(`narrative::query_properties`),所以读者的参数不会与投影实际接受的不一致。 + 把手属于显示它的那条线(§4)。所读的线在两次调用之间可能变化的读者,比如成员的当前线会变,可能拿着新线上没有的把手;这个把手与任何未知 id 一样被拒绝(§6),拒绝消息告诉读者不带 `open` 或 `before` 再读一次,从它现在所读的线的最近几轮开始。 ## 4. 把手:时间与事件 id @@ -198,7 +200,7 @@ Recall 按块文本的开头标签与属性,以及 `InputBlock::Raw` 的 `key` | `name` | `recall` | | `risk` | `session` | | `source` | `extension` | -| `description` | "Recall what happened earlier in this conversation, including what a compaction summarized: what the user said, what you did and what came back. With no arguments it lists past turns; open a turn or anything in it by its id, or search with about. A shortened input that ends in [input ] is read in full by opening that id." | +| `description` | "Recall what happened earlier in this conversation, including what a compaction summarized: what the user said, what you did and what came back. With no arguments it lists past turns; open any line by its id, or search with about. A shortened input that ends in [input ] is read in full by opening that id." | 工具声明是唯一的提示词。摘要、replacement 和系统提示词都不提这个工具(§7)。 @@ -212,8 +214,8 @@ Recall 按块文本的开头标签与属性,以及 `InputBlock::Raw` 的 `key` "description": "Words to look for; all must appear, in any order, ignoring case."}, "tool": {"type": "string", "minLength": 1, "description": "Only calls to this tool."}, - "before": {"type": "string", "description": "An id; show what came before it."}, - "open": {"type": "string", "description": "An id; show that turn, or that thing in full."}, + "before": {"type": "string", "description": "A line's id; show what came before it."}, + "open": {"type": "string", "description": "A line's id; show it in full."}, "offset": {"type": "integer", "minimum": 0, "description": "With open: continue from here, a line of a turn or a character of one thing."} },