Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion crates/dim-agent-capabilities/src/narrative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 3 additions & 25 deletions crates/dim-agent-capabilities/src/recall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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 <id>] 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 <id>] 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
}),
);
Expand Down
20 changes: 8 additions & 12 deletions crates/dim-app-server/src/collaboration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.";

Expand All @@ -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"});
Expand Down
18 changes: 17 additions & 1 deletion crates/dim-app-server/tests/transport_flow/collaboration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(
Expand Down
28 changes: 28 additions & 0 deletions crates/dim-app-server/tests/transport_flow/recall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<Provider>>, Json(body): Json<Value>) -> String {
Expand Down Expand Up @@ -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());

Expand Down
10 changes: 7 additions & 3 deletions docs/design/plugins/Recall.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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 <id>] 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 <id>] 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).
Expand All @@ -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."}
},
Expand Down
8 changes: 5 additions & 3 deletions docs/zh/design/plugins/Recall.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <id>] 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 <id>] is read in full by opening that id." |

工具声明是唯一的提示词。摘要、replacement 和系统提示词都不提这个工具(§7)。

Expand All @@ -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."}
},
Expand Down