Session ops and ContextPolicy in hx-core
This commit is contained in:
1 parent
69d5ae4581
commit
be74dd9fec
7 files changed
+205
-105
No files matched your search
@@ -45,24 +45,17 @@ pub struct Switcher {
|
||||
kind: Kind,
|
||||
models: Vec<ModelInfo>,
|
||||
make_provider: MakeProvider,
|
||||
auto_compact: bool,
|
||||
}
|
||||
|
||||
impl Switcher {
|
||||
/// `kind` is the provider the agent starts with. `auto_compact`: re-derive the compaction
|
||||
/// threshold from the model's window on every switch (false when it is configured explicitly).
|
||||
pub fn new(
|
||||
kind: Kind,
|
||||
models: Vec<ModelInfo>,
|
||||
make_provider: MakeProvider,
|
||||
auto_compact: bool,
|
||||
) -> Self {
|
||||
/// `kind` is the provider the agent starts with. The agent's `ContextPolicy` decides whether a
|
||||
/// model switch moves the compaction threshold.
|
||||
pub fn new(kind: Kind, models: Vec<ModelInfo>, make_provider: MakeProvider) -> Self {
|
||||
Self {
|
||||
remember: None,
|
||||
kind,
|
||||
models,
|
||||
make_provider,
|
||||
auto_compact,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,9 +115,7 @@ impl Switcher {
|
||||
let _ = serde_json::to_vec(&*l).map(|b| std::fs::write(&*p, b));
|
||||
}
|
||||
let window = models::window(&self.models, &model);
|
||||
if self.auto_compact {
|
||||
agent.fit_window(window);
|
||||
}
|
||||
agent.set_model_window(window);
|
||||
Ok(Switched {
|
||||
kind,
|
||||
model,
|
||||
@@ -184,7 +175,6 @@ mod tests {
|
||||
Ok(Arc::new(Nop))
|
||||
}
|
||||
}),
|
||||
auto,
|
||||
);
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let cx = ToolCtx {
|
||||
@@ -197,6 +187,9 @@ mod tests {
|
||||
Session::open(dir.path().join("s.jsonl")).unwrap(),
|
||||
cx,
|
||||
);
|
||||
if auto {
|
||||
a.set_context_policy(crate::window::ContextPolicy::FromModel { window: 0 });
|
||||
}
|
||||
a.set_model("claude-sonnet-x");
|
||||
(sw, a, made, dir)
|
||||
}
|
||||
@@ -285,7 +278,7 @@ mod tests {
|
||||
#[test]
|
||||
fn configured_threshold_is_left_alone() {
|
||||
let (mut sw, mut a, _m, _d) = setup(false, false);
|
||||
a.set_compact_at(12_345);
|
||||
a.set_context_policy(crate::window::ContextPolicy::Fixed(12_345));
|
||||
sw.set_model(&mut a, "claude-haiku-x").unwrap();
|
||||
assert_eq!(a.compact_at(), 12_345);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user