The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(host_runtime): restore agent chat turn checkpointing
Steven Enamakel795308dc03da
diff --git a/crates/openhuman-core/src/agent/session_host/turn_checkpoint.rs b/crates/openhuman-core/src/agent/session_host/turn_checkpoint.rsindex 9b0d18412e..4acd03d354 100644--- a/crates/openhuman-core/src/agent/session_host/turn_checkpoint.rs+++ b/crates/openhuman-core/src/agent/session_host/turn_checkpoint.rs@@ -82,15 +82,33 @@ conclusion yet, say that plainly and name what is missing.";/// persisting rather than gathering. A turn with nothing to persist loses that/// round — which is the cost of making the artifact structural instead of/// merely requested.+///+/// # A code change is not a file to write (#6958)+///+/// This used to say that "an incomplete file that marks its gaps honestly is+/// worth far more than no file at all". For a report or a guide that is true.+/// For a code change it steered a DeepSWE run that had made no source edits+/// into writing `ROLLING_WINDOW_IMPLEMENTATION_NOTES.md` into the user's repo:+/// the only "file" it could produce in one call was a description of the+/// change. So the wording now splits the two cases. A requested file is+/// still written; a code task applies real edits to its source files, and a+/// notes, plan or summary file in the project is ruled out by name, because a+/// partial set of real edits is the only partial result a code task can use.+/// What is left undone belongs in the reply, which the next call asks for.pub(crate) const FINAL_WRITE_INSTRUCTION: &str = "\This is the last call on which you can use a tool, and the only tools left are the ones that write files. \Gathering is over — anything you have not found by now will not be found in this turn.\n\\n\-If this task asked you to produce a file and you have not written it yet, write it now, from what is already in the \-results above. An incomplete file that marks its gaps honestly is worth far more than no file at all: write down what \-you did establish, and say explicitly inside the file which parts you could not confirm.\n\+If this task asked you to produce a file (a report, a guide, a document) and you have not written it yet, write it now \+with file_write, from what is already in the results above, and mark inside it any part you could not confirm.\n\+\n\+If this task is a code change, apply as much of the change as you can right now as real edits to the source files: \+apply_patch for targeted edits, or file_write to rewrite a file whose full content you have. A partial set of real \+edits is worth more than any description of them. Do not write notes, a plan, a summary, a TODO list or any other \+document into the project in place of the change. If you cannot edit a file exactly, leave it untouched and name it \+in your reply.\n\\n\-If there is nothing to write — the task asked only for an answer, or you have already written the file — then do not \+If there is nothing to write — the task asked only for an answer, or the work is already written — then do not \call a tool. Answer instead, and you will be asked to conclude next.";/// One completed tool call, carrying enough of its **actual output** to standdiff --git a/crates/openhuman-core/src/config/schema/load/env_overlay.rs b/crates/openhuman-core/src/config/schema/load/env_overlay.rsindex 0b592e0b5c..c72496e4f4 100644--- a/crates/openhuman-core/src/config/schema/load/env_overlay.rs+++ b/crates/openhuman-core/src/config/schema/load/env_overlay.rs@@ -105,6 +105,29 @@ impl Config {}}+ // Explicit tool-iteration cap that wins over every agent definition's+ // (#6958; see `session_host::builder::iteration_cap`). A positive+ // integer; anything else is ignored with a warning.+ if let Some(raw) = env.get("OPENHUMAN_AGENT_MAX_TOOL_ITERATIONS") {+ let trimmed = raw.trim();+ if !trimmed.is_empty() {+ match trimmed.parse::<usize>() {+ Ok(cap) if cap > 0 => {+ tracing::debug!(+ cap,+ "OPENHUMAN_AGENT_MAX_TOOL_ITERATIONS overrides \+ agent.max_tool_iterations_override"+ );+ self.agent.max_tool_iterations_override = Some(cap);+ }+ _ => tracing::warn!(+ value = trimmed,+ "OPENHUMAN_AGENT_MAX_TOOL_ITERATIONS is not a positive integer; ignored"+ ),+ }+ }+ }+// One-launch override of `composio.mode`: `backend | direct | disabled`.// The factory rejects an unknown spelling loudly, so no validation here.if let Some(raw) = env.get("OPENHUMAN_COMPOSIO_MODE") {diff --git a/crates/openhuman-core/src/inference/host_runtime/ops.rs b/crates/openhuman-core/src/inference/host_runtime/ops.rsindex 8b28bb3d87..e0da5ce334 100644--- a/crates/openhuman-core/src/inference/host_runtime/ops.rs+++ b/crates/openhuman-core/src/inference/host_runtime/ops.rs@@ -12,7 +12,10 @@ mod agent_chat;mod runtime_ops;mod turn_guards;-pub use agent_chat::{agent_chat, agent_chat_for, agent_chat_simple, AgentChatTarget};+pub use agent_chat::{+ agent_chat, agent_chat_for, agent_chat_reply_for, agent_chat_simple, AgentChatReply,+ AgentChatTarget,+};pub use runtime_ops::{local_ai_prompt, local_ai_status, local_ai_summarize, local_ai_transcribe,local_ai_transcribe_bytes, local_ai_tts, local_ai_vision_prompt,diff --git a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rsindex e9d8190c27..b4aa7160e3 100644--- a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs+++ b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs@@ -91,9 +91,28 @@ impl AgentChatReply {Outcome::single_log(self.text, AGENT_CHAT_COMPLETED_LOG)}- /// stub+ /// The `inference.agent_chat` wire shape: the historical+ /// `{"result": <text>, "logs": [...]}` envelope plus `hit_cap`, and, when+ /// the turn was capped, `checkpoint` (the same text, named for what it is).+ ///+ /// Additive on purpose: existing clients keep reading the reply from+ /// `result` (directly or through `unwrap_rpc`), and a headless caller can+ /// now tell a capped turn from a finished one and continue it (#6958).pub fn into_rpc_json(self) -> Result<serde_json::Value, String> {- self.into_outcome().into_cli_compatible_json()+ let hit_cap = self.hit_cap;+ let checkpoint = hit_cap.then(|| self.text.clone());+ let mut value = self.into_outcome().into_cli_compatible_json()?;+ let serde_json::Value::Object(map) = &mut value else {+ return Err("agent chat envelope is not a JSON object".to_string());+ };+ map.insert("hit_cap".to_string(), serde_json::Value::Bool(hit_cap));+ if let Some(checkpoint) = checkpoint {+ map.insert(+ "checkpoint".to_string(),+ serde_json::Value::String(checkpoint),+ );+ }+ Ok(value)}}@@ -211,6 +230,33 @@ pub async fn agent_chat_for(cwd: Option<String>,route: Option<crate::config::schema::EphemeralRoute>,) -> Result<Outcome<String>, String> {+ agent_chat_reply_for(+ config,+ target,+ message,+ model_override,+ temperature,+ thread_id,+ cwd,+ route,+ )+ .await+ .map(AgentChatReply::into_outcome)+}++/// [`agent_chat_for`], keeping whether the turn stopped at its iteration cap.+/// The `inference.agent_chat` controller answers from this.+#[allow(clippy::too_many_arguments)]+pub async fn agent_chat_reply_for(+ config: &mut Config,+ target: AgentChatTarget<'_>,+ message: &str,+ model_override: Option<String>,+ temperature: Option<f64>,+ thread_id: Option<String>,+ cwd: Option<String>,+ route: Option<crate::config::schema::EphemeralRoute>,+) -> Result<AgentChatReply, String> {enforce_user_prompt_or_reject(message, "local_ai.ops.agent_chat")?;// TAURI-RUST-RS: an upstream caller (frontend, JSON-RPC client) can pass@@ -348,8 +394,12 @@ pub async fn agent_chat_for(.lock().unwrap_or_else(std::sync::PoisonError::into_inner) = agent.last_turn_usage();}- let response = outcome.map_err(|e| e.to_string())?;- Ok(Outcome::single_log(response, "agent chat completed"))+ let text = outcome.map_err(|e| e.to_string())?;+ let hit_cap = agent.last_turn_hit_cap();+ if hit_cap {+ log::info!("[inference] agent_chat turn paused at its iteration cap; reporting hit_cap");+ }+ Ok(AgentChatReply { text, hit_cap })}/// A simplified chat interface that does not update the base configuration.diff --git a/crates/openhuman-core/src/inference/host_runtime/schemas.rs b/crates/openhuman-core/src/inference/host_runtime/schemas.rsindex 9fec641e1d..04e302f274 100644--- a/crates/openhuman-core/src/inference/host_runtime/schemas.rs+++ b/crates/openhuman-core/src/inference/host_runtime/schemas.rs@@ -138,7 +138,12 @@ pub fn schemas(function: &str) -> ControllerSchema {endpoint alone.",),],- outputs: vec![json_output("response", "Agent response payload.")],+ outputs: vec![json_output(+ "response",+ "Agent response payload: `result` (the reply text), `logs`, `hit_cap` (true when \+ the turn stopped at its tool-iteration cap instead of finishing) and, only when \+ hit_cap is true, `checkpoint` (the resumable checkpoint text, equal to `result`).",+ )],},"agent_chat_simple" => ControllerSchema {namespace: "inference",@@ -219,19 +224,18 @@ fn handle_agent_chat(params: Map<String, Value>) -> ControllerFuture {}_ => crate::inference::host_runtime::ops::AgentChatTarget::Orchestrator,};- to_json(- crate::inference::host_runtime::ops::agent_chat_for(- &mut config,- target,- &p.message,- p.model_override,- p.temperature,- p.thread_id,- p.cwd,- crate::config::schema::EphemeralRoute::from_params(p.inference_url, p.api_key),- )- .await?,+ crate::inference::host_runtime::ops::agent_chat_reply_for(+ &mut config,+ target,+ &p.message,+ p.model_override,+ p.temperature,+ p.thread_id,+ p.cwd,+ crate::config::schema::EphemeralRoute::from_params(p.inference_url, p.api_key),)+ .await?+ .into_rpc_json()})}