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
refactor(agent_chat): move agent chat reply and tests into dedicated modules
Steven Enamakel17c457800105
diff --git a/crates/openhuman-core/src/agent_runs/agent_chat/controllers.rs b/crates/openhuman-core/src/agent_runs/agent_chat/controllers.rsindex 20afc84bdb..1ef4f91f86 100644--- a/crates/openhuman-core/src/agent_runs/agent_chat/controllers.rs+++ b/crates/openhuman-core/src/agent_runs/agent_chat/controllers.rs@@ -5,6 +5,10 @@ use crate::agent_runs::agent_chat::params::AgentChatParams;use crate::core::all::{ControllerFuture, RegisteredController};use crate::core::{ControllerSchema, FieldSchema, TypeSchema};+#[cfg(test)]+#[path = "controllers_tests.rs"]+mod tests;+#[derive(Debug, Deserialize)]struct InferenceAgentChatParams {#[serde(flatten)]diff --git a/crates/openhuman-core/src/agent_runs/agent_chat/controllers_tests.rs b/crates/openhuman-core/src/agent_runs/agent_chat/controllers_tests.rsnew file mode 100644index 0000000000..2e202258f7--- /dev/null+++ b/crates/openhuman-core/src/agent_runs/agent_chat/controllers_tests.rs@@ -0,0 +1,40 @@+use super::*;++#[test]+fn inference_agent_chat_controllers_keep_their_wire_names_and_namespace() {+ let controllers = all_registered_controllers();+ assert_eq!(controllers.len(), 2);+ assert_eq!(controllers[0].rpc_method_name(), crate::agent_runs::INFERENCE_AGENT_CHAT);+ assert_eq!(controllers[0].schema.namespace, "inference");+ assert_eq!(controllers[0].schema.function, "agent_chat");+ assert_eq!(controllers[1].schema.function, "agent_chat_simple");+}++#[test]+fn ordinary_agent_chat_still_ignores_inference_only_fields() {+ let params: AgentChatParams = serde_json::from_value(serde_json::json!({+ "message": "hello",+ "inference_url": 7,+ "api_key": {"unexpected": true},+ "inference_headers": "malformed",+ "agent_id": false+ }))+ .expect("unknown inference-only fields remain ignored on agent.chat");+ assert_eq!(params.message, "hello");+ assert!(params.cwd.is_none());+}++#[test]+fn inference_agent_chat_parses_its_route_fields() {+ let params: InferenceAgentChatParams = serde_json::from_value(serde_json::json!({+ "message": "hello",+ "agent_id": "alpha",+ "inference_url": "https://example.test/v1",+ "api_key": "secret",+ "inference_headers": [["x-test", "value"]]+ }))+ .expect("inference route params decode");+ assert_eq!(params.agent_id.as_deref(), Some("alpha"));+ assert_eq!(params.inference_url.as_deref(), Some("https://example.test/v1"));+ assert_eq!(params.inference_headers, vec![("x-test".into(), "value".into())]);+}diff --git a/crates/openhuman-core/src/agent_runs/agent_chat/envelope.rs b/crates/openhuman-core/src/agent_runs/agent_chat/envelope.rsnew file mode 100644index 0000000000..8eb72f72a4--- /dev/null+++ b/crates/openhuman-core/src/agent_runs/agent_chat/envelope.rs@@ -0,0 +1,47 @@+use crate::core::Outcome;++/// The log line every successful agent chat turn carries.+const AGENT_CHAT_COMPLETED_LOG: &str = "agent chat completed";++/// What one agent chat turn produced: its reply and whether it stopped at the+/// tool-iteration cap rather than finishing.+#[derive(Debug, Clone, PartialEq, Eq)]+pub struct AgentChatReply {+ /// The reply text. When `hit_cap` is set this is the turn's checkpoint.+ pub text: String,+ /// The turn paused at its iteration cap (see+ /// [`OpenHumanSessionHost::last_turn_hit_cap`]).+ pub hit_cap: bool,+}++impl AgentChatReply {+ /// The historical `Outcome<String>` shape, for library callers.+ pub fn into_outcome(self) -> Outcome<String> {+ Outcome::single_log(self.text, AGENT_CHAT_COMPLETED_LOG)+ }++ /// 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> {+ 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)+ }+}+diff --git a/crates/openhuman-core/src/agent_runs/agent_chat/session_turn.rs b/crates/openhuman-core/src/agent_runs/agent_chat/session_turn.rsindex acae9b1509..b2f5f99a05 100644--- a/crates/openhuman-core/src/agent_runs/agent_chat/session_turn.rs+++ b/crates/openhuman-core/src/agent_runs/agent_chat/session_turn.rs@@ -98,51 +98,6 @@ pub struct AgentChatEnv {>,}-/// The log line every successful agent chat turn carries.-const AGENT_CHAT_COMPLETED_LOG: &str = "agent chat completed";--/// What one agent chat turn produced: its reply and whether it stopped at the-/// tool-iteration cap rather than finishing.-#[derive(Debug, Clone, PartialEq, Eq)]-pub struct AgentChatReply {- /// The reply text. When `hit_cap` is set this is the turn's checkpoint.- pub text: String,- /// The turn paused at its iteration cap (see- /// [`OpenHumanSessionHost::last_turn_hit_cap`]).- pub hit_cap: bool,-}--impl AgentChatReply {- /// The historical `Outcome<String>` shape, for library callers.- pub fn into_outcome(self) -> Outcome<String> {- Outcome::single_log(self.text, AGENT_CHAT_COMPLETED_LOG)- }-- /// 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> {- 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)- }-}-/// Which session [`agent_chat_for`] builds the turn on.#[derive(Clone, Copy)]pub enum AgentChatTarget<'a> {diff --git a/crates/openhuman-core/src/inference/host_runtime/schemas_tests.rs b/crates/openhuman-core/src/inference/host_runtime/schemas_tests.rsindex 5cf3728c62..057f73dcb8 100644--- a/crates/openhuman-core/src/inference/host_runtime/schemas_tests.rs+++ b/crates/openhuman-core/src/inference/host_runtime/schemas_tests.rs@@ -12,8 +12,6 @@ fn all_schemas_use_inference_namespace_and_have_descriptions() {#[test]fn every_registered_key_resolves_to_non_unknown_schema() {let keys = [- "agent_chat",- "agent_chat_simple","transcribe","transcribe_bytes","tts",@@ -77,45 +75,3 @@ fn to_json_wraps_rpc_outcome() {assert!(v.get("logs").is_some() || v.get("result").is_some() || v.get("ok").is_some());}-#[test]-fn deserialize_params_parses_valid_object() {- let mut m = Map::new();- m.insert("message".into(), Value::String("hi".into()));- let p: AgentChatParams = deserialize_params(m).expect("parse");- assert_eq!(p.message, "hi");-}--#[test]-fn deserialize_params_errors_on_invalid_shape() {- let mut m = Map::new();- m.insert("message".into(), Value::Bool(true));- let err = deserialize_params::<AgentChatParams>(m).unwrap_err();- assert!(err.contains("invalid params"));-}--/// `agent_id` is a declared, optional input of `inference.agent_chat` — the-/// embed crate pins its `TurnRequest` field names against this schema, so a-/// param the controller accepts but never declares would be unreachable.-#[test]-fn agent_chat_declares_an_optional_agent_id() {- let schema = schemas("agent_chat");- let field = schema- .inputs- .iter()- .find(|f| f.name == "agent_id")- .expect("agent_chat declares agent_id");- assert!(!field.required, "agent_id must stay optional");-}--/// The params struct accepts the field and, absent, defaults it to `None`, so-/// every existing caller keeps running the orchestrator.-#[test]-fn agent_chat_params_default_agent_id_to_none() {- let without: AgentChatParams =- serde_json::from_value(serde_json::json!({ "message": "hi" })).expect("decodes");- assert!(without.agent_id.is_none());- let with: AgentChatParams =- serde_json::from_value(serde_json::json!({ "message": "hi", "agent_id": "alpha" }))- .expect("decodes");- assert_eq!(with.agent_id.as_deref(), Some("alpha"));-}