Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(agent): preserve history cap after session migration

Steven Enamakel8be191cd92c3
diff --git a/crates/openhuman-core/src/agent/agent_turn_loop_tests.rs b/crates/openhuman-core/src/agent/agent_turn_loop_tests.rs
index 804e6d2283..bd45009886 100644
--- a/crates/openhuman-core/src/agent/agent_turn_loop_tests.rs
+++ b/crates/openhuman-core/src/agent/agent_turn_loop_tests.rs
@@ -128,7 +128,7 @@ async fn turn_emits_checkpoint_at_max_iterations() {
.await
.expect("hitting the iteration cap should return a checkpoint, not error");
assert!(
- reply.contains("tool-call limit") && reply.contains("Next steps"),
+ reply.contains("tool call") && reply.contains("Tell me how you'd like to proceed"),
"Expected a resumable checkpoint summary, got: {reply}"
);
// The transcript ends on the assistant checkpoint (well-formed), which
@@ -137,7 +137,7 @@ async fn turn_emits_checkpoint_at_max_iterations() {
matches!(
agent.history().last(),
Some(ConversationMessage::Chat(msg))
- if msg.role == "assistant" && msg.content.contains("Next steps")
+ if msg.role == "assistant" && msg.content.contains("Tell me how you'd like to proceed")
),
"history should end on the assistant checkpoint, got: {:?}",
agent.history().last()
@@ -424,13 +424,13 @@ async fn turn_errors_on_empty_text_response() {
let (mut agent, _tmp) = build_agent_with(provider, vec![], Box::new(NativeDialect));
- let err = agent
+ let reply = agent
.turn("hi")
.await
- .expect_err("an empty provider response should surface as an error");
+ .expect("an empty provider response should be closed");
assert!(
- err.to_string().contains("empty response"),
- "expected an empty-response error, got: {err}"
+ reply.contains("produced no result"),
+ "expected a deterministic empty-response close, got: {reply}"
);
}
@@ -445,13 +445,13 @@ async fn turn_errors_on_none_text_response() {
let (mut agent, _tmp) = build_agent_with(provider, vec![], Box::new(NativeDialect));
- let err = agent
+ let reply = agent
.turn("hi")
.await
- .expect_err("a null-text provider response should surface as an error");
+ .expect("a null-text provider response should be closed");
assert!(
- err.to_string().contains("empty response"),
- "expected an empty-response error, got: {err}"
+ reply.contains("produced no result"),
+ "expected a deterministic empty-response close, got: {reply}"
);
}
diff --git a/crates/openhuman-core/src/agent/session_host/driver.rs b/crates/openhuman-core/src/agent/session_host/driver.rs
index e8e2b4770f..505afc8167 100644
--- a/crates/openhuman-core/src/agent/session_host/driver.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver.rs
@@ -32,6 +32,7 @@ pub struct OpenHumanSessionDriver {
model_name: String,
temperature: f64,
max_iterations: usize,
+ max_history_messages: usize,
model_vision: bool,
run_queue:
Option<Arc<tinyagents_harness::run_queue::RunQueue<crate::agent::queued_turn::QueuedTurn>>>,
@@ -49,6 +50,7 @@ impl OpenHumanSessionDriver {
model_name: String,
temperature: f64,
max_iterations: usize,
+ max_history_messages: usize,
model_vision: bool,
run_queue: Option<
Arc<tinyagents_harness::run_queue::RunQueue<crate::agent::queued_turn::QueuedTurn>>,
@@ -64,6 +66,7 @@ impl OpenHumanSessionDriver {
model_name,
temperature,
max_iterations,
+ max_history_messages,
model_vision,
run_queue,
workspace,
@@ -255,6 +258,7 @@ impl SessionDriver<OpenHumanRunContext> for OpenHumanSessionDriver {
appended.push(Message::assistant(output.clone()));
}
history.extend(appended);
+ trim_history(&mut history, self.max_history_messages);
let required_output = request.run_context.data.required_output.clone();
let required_repair = match required_output.as_ref() {
@@ -352,6 +356,22 @@ impl SessionDriver<OpenHumanRunContext> for OpenHumanSessionDriver {
}
}
+/// Keep the system prelude and the most recent conversation rows within the
+/// host-configured history budget. The runtime owns durable history, while the
+/// OpenHuman configuration remains the compatibility contract for callers.
+fn trim_history(history: &mut Vec<Message>, max_history_messages: usize) {
+ if history.len() <= max_history_messages.saturating_add(1) {
+ return;
+ }
+ let system = matches!(history.first(), Some(Message::System(_))).then(|| history.remove(0));
+ let keep = max_history_messages.min(history.len());
+ let start = history.len().saturating_sub(keep);
+ history.drain(..start);
+ if let Some(system) = system {
+ history.insert(0, system);
+ }
+}
+
fn driver_error(error: impl std::fmt::Display) -> DriverFailure {
driver_failure(error)
}
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index 165df0fd9d..0f503125ac 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -1473,6 +1473,7 @@ impl OpenHumanSessionHost {
self.model_name.clone(),
self.temperature,
self.config.max_tool_iterations,
+ self.config.max_history_messages,
self.model_vision,
self.run_queue.clone(),
self.workspace_descriptor.clone(),