Subagents: read-only explore, custom agents, background runs, limits
- explore's bash only runs commands the permit classifier calls read-only - custom kinds from <hx home>/agents/*.md and .hx/agents/*.md - task(background=true) + task(wait=[ids]); finished answers handed over at turn end - answers over 8 KB saved to <session>.sub/NNN-kind.answer.md - subagent_parallel / subagent_max_turns / subagent_max_tokens / subagent_timeout_secs Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
823110a518
commit
164671a0c5
7 files changed
+769
-56
No files matched your search
@@ -7,7 +7,11 @@
|
||||
# codex_model = "gpt-5.6-sol" # default: Codex's top-listed model
|
||||
# subagents = false # do not offer the `task` tool (default true; every call asks first)
|
||||
# explore_model = "claude-haiku-4-5" # read-only `task` subagents; default: cheapest tier of the provider
|
||||
# remember_model = true # reuse the last model picked with /model or /provider
|
||||
# subagent_parallel = 3 # subagents running at once
|
||||
# subagent_max_turns = 40 # turn limit per subagent (an agent file's max_turns wins)
|
||||
# subagent_max_tokens = 500000 # stop a subagent that spends more tokens than this; default: no limit
|
||||
# subagent_timeout_secs = 600 # stop a subagent run after this long; default: no limit
|
||||
# remember_model = true # reuse the last model picked with /model or /provider
|
||||
# compact_at = 900000 # auto-compact at this many tokens; default: 90% of the context window
|
||||
# max_tokens = 16384
|
||||
# permissions = "ask" # ask | auto (refuse dangerous calls, run safe ones) | yolo (nothing asks)
|
||||
|
||||
@@ -156,6 +156,10 @@ struct Config {
|
||||
max_tokens: Option<u32>,
|
||||
explore_model: Option<String>,
|
||||
subagents: Option<bool>,
|
||||
subagent_parallel: Option<usize>,
|
||||
subagent_max_turns: Option<u32>,
|
||||
subagent_max_tokens: Option<u64>,
|
||||
subagent_timeout_secs: Option<u64>,
|
||||
codemode: Option<bool>,
|
||||
mouse: Option<bool>,
|
||||
sessions_dir: Option<String>,
|
||||
@@ -220,6 +224,10 @@ impl Config {
|
||||
max_tokens: o.max_tokens.or(c.max_tokens),
|
||||
explore_model: o.explore_model.or(c.explore_model),
|
||||
subagents: o.subagents.or(c.subagents),
|
||||
subagent_parallel: o.subagent_parallel.or(c.subagent_parallel),
|
||||
subagent_max_turns: o.subagent_max_turns.or(c.subagent_max_turns),
|
||||
subagent_max_tokens: o.subagent_max_tokens.or(c.subagent_max_tokens),
|
||||
subagent_timeout_secs: o.subagent_timeout_secs.or(c.subagent_timeout_secs),
|
||||
codemode: o.codemode.or(c.codemode),
|
||||
mouse: o.mouse.or(c.mouse),
|
||||
sessions_dir: o.sessions_dir.or(c.sessions_dir),
|
||||
@@ -734,7 +742,16 @@ async fn main() -> Result<()> {
|
||||
rows.extend(skill_rows);
|
||||
let mut specs = reg.specs();
|
||||
if !cli.no_subagents && cfg.subagents != Some(false) {
|
||||
specs.push(hx_core::subagent::spec());
|
||||
let (defs, _) = hx_core::subagent::load_agents(&hx_core::subagent::agent_dirs(
|
||||
&hx_core::context::hx_home(),
|
||||
&cwd,
|
||||
));
|
||||
let mut kinds = hx_core::subagent::builtin_kinds();
|
||||
for d in defs {
|
||||
kinds.retain(|k| k.0 != d.name);
|
||||
kinds.push((d.name, d.description));
|
||||
}
|
||||
specs.push(hx_core::subagent::spec_for(&kinds));
|
||||
}
|
||||
specs.sort_by_key(|t| {
|
||||
std::cmp::Reverse(serde_json::to_string(t).map_or(0, |s| s.len()))
|
||||
@@ -1037,13 +1054,19 @@ async fn main() -> Result<()> {
|
||||
if !cli.no_subagents && cfg.subagents != Some(false) {
|
||||
let mut general = agent.tools.clone();
|
||||
general.retain(|n| n != "ask_user" && n != "exit_plan");
|
||||
let base = general.clone();
|
||||
let mut explore = agent.tools.clone();
|
||||
explore.retain(|n| hx_core::subagent::EXPLORE_TOOLS.contains(&n));
|
||||
if let Some(b) = explore.get("bash") {
|
||||
explore.add(hx_core::subagent::ReadOnlyBash(b));
|
||||
}
|
||||
let role = |model: String, tools, base: &str| hx_core::subagent::Role {
|
||||
provider: provider(kind).expect("provider worked above"),
|
||||
model,
|
||||
tools,
|
||||
system: format!("{base}{tail}"),
|
||||
hooks: false,
|
||||
max_turns: None,
|
||||
};
|
||||
let cheap = cfg
|
||||
.explore_model
|
||||
@@ -1051,19 +1074,56 @@ async fn main() -> Result<()> {
|
||||
.or_else(|| hx_ai::models::cheap_for(kind, &models))
|
||||
.unwrap_or_else(|| agent.model().to_string());
|
||||
let mut task = hx_core::subagent::Task::new(
|
||||
role(cheap, explore, hx_core::subagent::EXPLORE_PROMPT),
|
||||
role(cheap.clone(), explore, hx_core::subagent::EXPLORE_PROMPT),
|
||||
role(
|
||||
agent.model().to_string(),
|
||||
general,
|
||||
hx_core::subagent::GENERAL_PROMPT,
|
||||
),
|
||||
path.with_extension("sub"),
|
||||
3,
|
||||
cfg.subagent_parallel.unwrap_or(3),
|
||||
);
|
||||
if let Some(n) = cfg.subagent_max_turns {
|
||||
task.max_turns = n;
|
||||
}
|
||||
task.max_tokens = cfg.subagent_max_tokens;
|
||||
task.timeout = cfg
|
||||
.subagent_timeout_secs
|
||||
.map(std::time::Duration::from_secs);
|
||||
if let Some(l) = &lens_ref {
|
||||
task.hooks.push(Arc::new(ArcHook(l.clone())));
|
||||
}
|
||||
let (defs, warns) = hx_core::subagent::load_agents(&hx_core::subagent::agent_dirs(
|
||||
&context::hx_home(),
|
||||
&cwd,
|
||||
));
|
||||
for w in warns {
|
||||
eprintln!("hx: agent {w}");
|
||||
}
|
||||
for d in defs {
|
||||
let tools = hx_core::subagent::agent_tools(&base, &d);
|
||||
let (model, default_prompt) = if d.readonly {
|
||||
(cheap.clone(), hx_core::subagent::EXPLORE_PROMPT)
|
||||
} else {
|
||||
(agent.model().to_string(), hx_core::subagent::GENERAL_PROMPT)
|
||||
};
|
||||
let mut r = role(
|
||||
d.model.clone().unwrap_or(model),
|
||||
tools,
|
||||
if d.system.is_empty() {
|
||||
default_prompt
|
||||
} else {
|
||||
&d.system
|
||||
},
|
||||
);
|
||||
r.hooks = hx_core::subagent::edits(&r.tools);
|
||||
r.max_turns = d.max_turns;
|
||||
task.add_kind(d.name, d.description, r);
|
||||
}
|
||||
agent.tools.add(task);
|
||||
agent
|
||||
.bus
|
||||
.add(hx_core::subagent::Notify(agent.cx.state.clone()));
|
||||
}
|
||||
if CLAUDE_CLI.get().is_none()
|
||||
&& let (Ok(p), Some(model)) = (
|
||||
|
||||
Reference in new issue
Block a user