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
feat(subagent_host): add checkpoint ops for subagent host
Steven Enamakelf2d260aeadb3
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/checkpoint.rs b/crates/openhuman-core/src/agent/subagent_host/ops/checkpoint.rsnew file mode 100644index 0000000000..875276fcf3--- /dev/null+++ b/crates/openhuman-core/src/agent/subagent_host/ops/checkpoint.rs@@ -0,0 +1,84 @@+//! OpenHuman billing adapter for TinyAgents' cap-hit checkpoint summary.++use crate::inference::provider::BilledUsage;+use std::sync::{Arc, Mutex};+use tinyagents_harness::summarization::CapToolResult;+use tinyinference_llm::message::Message;+use tinyinference_llm::model::{ChatModel, ModelRequest};+use tinyagents_orchestration::subagent::{CapSummaryModel, summarize_at_cap};++/// The provider usage from a summary call, charged by the host after the owner+/// API applies its shared digest and fallback policy.+pub(super) struct SubagentCheckpointOutcome {+ pub(super) text: String,+ pub(super) usage: Option<BilledUsage>,+}++/// The host owns provider invocation and billing; TinyAgents owns summary+/// selection, deterministic fallback, and the bounded tool-result digest.+pub(super) struct SubagentCheckpoint {+ pub(super) chat_model: Arc<dyn ChatModel<()>>,+ pub(super) agent_id: String,+ pub(super) max_output_tokens: u32,+}++impl SubagentCheckpoint {+ pub(super) async fn summarize_cap_hit(+ &self,+ results: &[CapToolResult<'_>],+ max_iterations: usize,+ ) -> anyhow::Result<SubagentCheckpointOutcome> {+ let model = HostCapSummaryModel {+ checkpoint: self,+ usage: Mutex::new(None),+ };+ let summary = summarize_at_cap(Some(&model), max_iterations, results, 800).await;+ let usage = model+ .usage+ .into_inner()+ .unwrap_or_else(|poisoned| poisoned.into_inner());+ Ok(SubagentCheckpointOutcome {+ text: summary.text,+ usage,+ })+ }+}++struct HostCapSummaryModel<'a> {+ checkpoint: &'a SubagentCheckpoint,+ usage: Mutex<Option<BilledUsage>>,+}++#[async_trait::async_trait]+impl CapSummaryModel for HostCapSummaryModel<'_> {+ async fn summarize(&self, max_calls: usize, digest: &str) -> Result<String, String> {+ let summary_input = vec![Message::user(format!(+ "You are sub-agent `{}` and reached your tool-call limit before finishing. Here are \+ the tool calls you made and their results — compile a brief progress checkpoint (what you \+ accomplished, what still remains) for the agent that delegated to you. Do not call tools.\n\n{digest}",+ self.checkpoint.agent_id,+ ))];+ let request = ModelRequest::new(summary_input)+ .with_max_tokens(self.checkpoint.max_output_tokens);+ match self.checkpoint.chat_model.invoke(&(), request).await {+ Ok(response) => {+ let usage = crate::inference::provider::model::usage_info_from_response(&response);+ *self+ .usage+ .lock()+ .unwrap_or_else(|poisoned| poisoned.into_inner()) = usage;+ let (prose, _) = tinytools_agent::parse_tool_calls(&response.text());+ Ok(prose)+ }+ Err(error) => {+ tracing::warn!(+ agent_id = %self.checkpoint.agent_id,+ max_calls,+ error = %error,+ "[subagent_host] checkpoint summary call failed — using deterministic fallback"+ );+ Err(error.to_string())+ }+ }+ }+}