Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

refactor(agent): stop advertising await_subagent, list_work, read_agent

Akarshan Biswas9bcef390de3c
diff --git a/src-tauri/src/core/agent/context.rs b/src-tauri/src/core/agent/context.rs
index 5132e1d3d..cb4350179 100644
--- a/src-tauri/src/core/agent/context.rs
+++ b/src-tauri/src/core/agent/context.rs
@@ -140,8 +140,9 @@ const SUBAGENT_GUIDE: &str = "# Subagents\n\nYour own context window is limited.
that could pull in a lot of file content or tool output (broad codebase search, reading files, many \
multi-step research), prefer `dispatch_subagent` over doing it inline: the subagent absorbs that context \
in its own window and returns only the distilled answer. Dispatch independent subagents in parallel when \
-their work doesn't depend on each other, then `await_subagent` each. Do inline work yourself for small, \
-targeted tasks where delegating would cost more than it saves.";
+their work doesn't depend on each other; each returns in the background and a note carries its answer when \
+it finishes -- keep working rather than waiting. Do inline work yourself for small, targeted tasks where \
+delegating would cost more than it saves.";
/// The worker half of the work-queue guide, shown to every collaborating agent
/// (main and workers), so a worker knows the claim -> do -> complete -> stop loop
@@ -149,8 +150,7 @@ targeted tasks where delegating would cost more than it saves.";
const WORK_QUEUE_WORKER_GUIDE: &str = "# Shared work queue\n\nYou share a work queue and a live status \
board with the other agents on this run. As a worker: call `claim_work` to take the next ready task, do \
it, then `complete_work` with the result. If `claim_work` reports nothing is ready, stop -- do not loop \
-on it; you are re-dispatched when new work appears. `list_work` shows the whole queue, and `read_agent` \
-shows what any agent is doing (call it with no argument for the roster of every agent).";
+on it; you are re-dispatched when new work appears.";
/// The dispatcher half, added only for a run that may dispatch subagents (main),
/// so it learns the post -> dispatch-workers -> chain-with-deps pattern and the
diff --git a/src-tauri/src/core/agent/loop.rs b/src-tauri/src/core/agent/loop.rs
index 1da6068cf..719857afc 100644
--- a/src-tauri/src/core/agent/loop.rs
+++ b/src-tauri/src/core/agent/loop.rs
@@ -939,14 +939,12 @@ impl CompositeToolInvoker {
Some(path) => format!(
"Subagent started in the background. run_id={}. Its answer will be \
written to {path}; you will be told when it lands, so keep working \
- rather than waiting. Read that file when you need the answer, or \
- call await_subagent with this run_id to block until it is ready.",
+ rather than waiting, and read that file when you need the answer.",
d.run_id
),
None => format!(
- "Subagent started in the background. run_id={}. You will be told when \
- it finishes; keep working, then call await_subagent with this run_id \
- to collect its result.",
+ "Subagent started in the background. run_id={}. Keep working; you will \
+ be told when it finishes, and that note carries its answer.",
d.run_id
),
},
@@ -1964,6 +1962,13 @@ fn advertise_local_tools(
if permissions.is_denied(name) {
continue;
}
+ // await_subagent is not advertised: a finished child's note
+ // already carries its answer (inline, or a file path to
+ // read), so blocking to collect is redundant. The handler
+ // stays (recognized + executable) so a named call still works.
+ if name == "await_subagent" {
+ continue;
+ }
if let Some(allow) = allowed_names {
if !allow.contains(name) {
continue;
@@ -1983,14 +1988,18 @@ fn advertise_local_tools(
openai_tools.push(tauri_plugin_agent_tools::tools::monitor::monitor_tool_schema());
}
}
- // Work-queue + observability tools. Available to main AND to workers
- // (unlike subagent dispatch, which caps recursion), gated on
- // collaboration being enabled. The mutating three are hidden in Plan;
- // `read_agent`/`list_work` are read-only and stay.
+ // Work-queue tools, gated on collaboration being enabled. Available to
+ // main AND to workers (unlike subagent dispatch, which caps recursion).
+ // The mutating three are hidden in Plan mode. `list_work` and `read_agent`
+ // are not advertised: the queue and each peer's status are visible to the
+ // user (the panel and `/agents`), and a worker's claim->do->complete loop
+ // does not need to poll them -- dropping them also shrinks the schema and
+ // removes two thirds of the poll-only set. Both stay recognized and
+ // executable (handlers untouched) so a named call still works.
if work_queue_enabled {
for schema in tauri_plugin_agent_tools::tools::workqueue::work_tool_schemas() {
let name = schema["function"]["name"].as_str().unwrap_or_default();
- if permissions.is_denied(name) {
+ if name == "list_work" || permissions.is_denied(name) {
continue;
}
if planning && tauri_plugin_agent_tools::tools::workqueue::is_work_mutation(name) {
@@ -2001,13 +2010,6 @@ fn advertise_local_tools(
}
openai_tools.push(schema);
}
- let read_agent = tauri_plugin_agent_tools::tools::observ::read_agent_tool_schema();
- let ra_name = read_agent["function"]["name"].as_str().unwrap_or_default();
- if !permissions.is_denied(ra_name)
- && allowed_names.is_none_or(|allowed| allowed.contains(ra_name))
- {
- openai_tools.push(read_agent);
- }
}
}
// The `ask` tool needs no project (it's an interactive question, not
diff --git a/src-tauri/src/core/agent/subagent.rs b/src-tauri/src/core/agent/subagent.rs
index 754d9b687..94eb35d17 100644
--- a/src-tauri/src/core/agent/subagent.rs
+++ b/src-tauri/src/core/agent/subagent.rs
@@ -11,7 +11,9 @@ use serde::{Deserialize, Serialize};
use tauri_plugin_agent_tools::permissions::ToolPermissions;
use tauri_plugin_agent_tools::tools::sandbox::scratch_display_path;
-use tauri_plugin_agent_tools::tools::spill::{fill_subagent_result, reserve_subagent_result};
+use tauri_plugin_agent_tools::tools::spill::{
+ compose_subagent_result, fill_subagent_result, reserve_subagent_result,
+};
use tauri_plugin_agent_tools::workspace;
/// Directory name holding `<name>.toml` definitions, under both a project's
@@ -1227,11 +1229,13 @@ fn completion_notice(
(Err(e), _) => format!("Subagent '{name}' ({run_id}) failed: {e}"),
(Ok(_), Some(path)) => format!(
"Subagent '{name}' ({run_id}) finished. Its full answer is in {path} -- read that file \
- when you need it. Do not call await_subagent for this run."
+ when you need it."
),
- (Ok(_), None) => format!(
- "Subagent '{name}' ({run_id}) finished. Call await_subagent with that run_id to read \
- its answer."
+ // No spill file (an unconfined run has no scratch): the answer has
+ // nowhere to be read from later, so it rides the note inline, bounded.
+ (Ok(text), None) => format!(
+ "Subagent '{name}' ({run_id}) finished. Its answer:\n\n{}",
+ compose_subagent_result(text, None)
),
}
}
@@ -1316,7 +1320,7 @@ pub fn subagent_tool_schemas(
names
};
let one_off = " For a one-off subagent, pass system_prompt inline (with a descriptive subagent_name); use create_subagent only to save a reusable definition.";
- let bg = format!(" Runs in the BACKGROUND and returns immediately with a run_id and the file its answer will be written to; keep working, dispatch more, and a note tells you the moment each one finishes. Awaiting is optional: call await_subagent(run_id) only to block until a specific child is done. Up to {max_parallel} run concurrently (max_parallel_subagents in agent.toml); dispatches beyond that are queued FIFO and start as running ones finish.");
+ let bg = format!(" Runs in the BACKGROUND and returns immediately with a run_id; keep working and dispatch more -- a note tells you the moment each one finishes and carries its answer (or the file its answer was written to). Up to {max_parallel} run concurrently (max_parallel_subagents in agent.toml); dispatches beyond that are queued FIFO and start as running ones finish.");
let dispatch_desc = if available.is_empty() {
format!("Start a subagent: a nested, isolated agent with its own system prompt and narrowed tools.{bg}{one_off} No saved subagents yet.")
} else {
@@ -1517,18 +1521,20 @@ mod tests {
std::fs::write(dir.join(format!("{name}.toml")), body).unwrap();
}
- /// The ping is what the parent gets when it never awaits, so it has to name
- /// the file -- and say plainly that awaiting is not the way to read it.
+ /// The ping is the only signal a non-awaiting parent gets, so it must carry
+ /// the answer: a file path when there is scratch, the bounded text inline
+ /// when there is not (await_subagent is no longer advertised).
#[test]
- fn the_completion_ping_names_the_reserved_file() {
+ fn the_completion_ping_delivers_the_answer() {
let ok = Ok("the findings".to_string());
let note = completion_notice("researcher", "sub-researcher-1", Some("/tmp/x.md"), &ok);
assert!(note.contains("/tmp/x.md"), "{note}");
- assert!(note.contains("Do not call await_subagent"), "{note}");
+ assert!(!note.contains("await_subagent"), "no await reference: {note}");
- // Unconfined: no file, so collecting is the only way to read it.
+ // Unconfined: no file, so the answer rides the note inline.
let note = completion_notice("researcher", "sub-researcher-1", None, &ok);
- assert!(note.contains("await_subagent"), "{note}");
+ assert!(note.contains("the findings"), "answer is inline: {note}");
+ assert!(!note.contains("await_subagent"), "no await reference: {note}");
let failed = Err(SubagentError::Upstream("upstream refused".to_string()));
let note = completion_notice("researcher", "sub-researcher-1", Some("/tmp/x.md"), &failed);
@@ -2521,7 +2527,10 @@ mod tests {
);
let dispatch = &schemas[0]["function"]["description"].as_str().unwrap();
assert!(dispatch.contains("reviewer"), "got: {dispatch}");
- assert!(dispatch.contains("await_subagent"), "dispatch should mention await");
+ // await_subagent is no longer advertised; the description explains the
+ // background model (a note carries each child's answer) instead.
+ assert!(!dispatch.contains("await_subagent"), "no await reference: {dispatch}");
+ assert!(dispatch.contains("BACKGROUND"), "explains the background model: {dispatch}");
}
#[test]