swarm: per-agent inference settings (model, effort, subagent_models) in KV
swarm-controller keeps each agent's inference settings in a new
`agent-inference` KV bucket, one key per agent, and is its only writer
(`GET`/`PUT`/`DELETE /api/agents/{name}/inference`; `swarmctl agent
inference get|set|clear`). Every field is optional. Each agent reads its
own key every 10 s through a direct-get grant on that key alone, and a
set `model` or `effort` replaces the Bus value, so the next turn runs on
it and the badge follows.
The swarm value is applied without persisting it: `Bus::set_model` and
`set_effort` are split into a persisting setter and a non-persisting
`apply_*`, and the poller uses the latter. Otherwise the swarm value
would overwrite `hyperhive-model`/`hyperhive-effort`, and clearing it, or
a restart, would no longer find the agent's own value. An unset field
changes nothing; a field cleared after being applied goes back to the
local value (`harness_state::local_model`/`local_effort`, the same
resolution `Bus::new` uses), read again at the clear.
`subagent_models` is validated, stored and shown by `get`; no agent
applies it yet.
Refs #5034
This commit is contained in:
parent
29d956140e
commit
916fdb35b8
24 changed files with 1432 additions and 34 deletions
|
|
@ -507,12 +507,14 @@ mod tests {
|
|||
"$SWARM.term.{agent}.sub.>",
|
||||
"--agent-token-publish-subject",
|
||||
"$JS.API.DIRECT.GET.KV_agent-schedules.$KV.agent-schedules.{agent}",
|
||||
"--agent-token-publish-subject",
|
||||
"$JS.API.DIRECT.GET.KV_agent-inference.$KV.agent-inference.{agent}",
|
||||
"--store-cert-role",
|
||||
"swarm-nats-auth",
|
||||
])
|
||||
.expect("the unit's own argument vector must parse");
|
||||
assert_eq!(args.agent_client_suffix, "-agent");
|
||||
assert_eq!(args.agent_token_publish_subjects.len(), 5);
|
||||
assert_eq!(args.agent_token_publish_subjects.len(), 6);
|
||||
}
|
||||
|
||||
/// A request with no `Nats-Server-Xkey` is dropped before anything reads
|
||||
|
|
|
|||
|
|
@ -1440,6 +1440,39 @@ mod tests {
|
|||
assert!(covers("$KV.*.>", &key_subject("argus")));
|
||||
}
|
||||
|
||||
/// The inference template as `swarm-nats.nix` spells it reads one key, the
|
||||
/// agent's own, and nothing that writes, watches or opens the bucket.
|
||||
#[test]
|
||||
fn an_agent_may_read_only_its_own_inference_key() {
|
||||
use swarm_queue_client::agent_inference::{STREAM, direct_get_subject, key_subject};
|
||||
|
||||
let p = policy()
|
||||
.with_agent_token_subjects(vec![
|
||||
"$JS.API.DIRECT.GET.KV_agent-inference.$KV.agent-inference.{agent}".to_owned(),
|
||||
])
|
||||
.expect("a per-agent template is valid");
|
||||
let atlas = p.agent_token_permissions("atlas").expect("configured");
|
||||
assert_eq!(atlas.publish, vec![direct_get_subject("atlas")]);
|
||||
let argus = p.agent_token_permissions("argus").expect("configured");
|
||||
assert_eq!(argus.publish, vec![direct_get_subject("argus")]);
|
||||
|
||||
for refused in [
|
||||
direct_get_subject("argus"),
|
||||
format!("$JS.API.DIRECT.GET.{STREAM}"),
|
||||
format!("$JS.API.STREAM.INFO.{STREAM}"),
|
||||
format!("$JS.API.CONSUMER.CREATE.{STREAM}"),
|
||||
key_subject("atlas"),
|
||||
swarm_queue_client::agent_schedules::direct_get_subject("atlas"),
|
||||
] {
|
||||
assert!(
|
||||
!atlas.publish.iter().any(|g| covers(g, &refused)),
|
||||
"atlas's grant covers {refused}"
|
||||
);
|
||||
}
|
||||
// Control: the matcher matches the one subject granted.
|
||||
assert!(covers(&atlas.publish[0], &direct_get_subject("atlas")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_agent_token_subject_without_the_placeholder_is_refused() {
|
||||
let err = policy()
|
||||
|
|
|
|||
Loading…
Reference in a new issue