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(tinyagents): use shared ephemeral instruction middleware
Steven Enamakel22fd47a22ea4
diff --git a/crates/openhuman-core/src/agent/message_convert_tests.rs b/crates/openhuman-core/src/agent/message_convert_tests.rsindex 9de7bd8529..9d6acf4d5f 100644--- a/crates/openhuman-core/src/agent/message_convert_tests.rs+++ b/crates/openhuman-core/src/agent/message_convert_tests.rs@@ -1,6 +1,6 @@use super::*;+use tinyagents_session::transcript::TranscriptToolCall;use tinyinference_llm::message::{AssistantMessage, ToolMessage};-use tinyagents_session::transcript::{TranscriptToolCall};#[test]fn durable_upload_parts_survive_message_row_replay_without_inline_payloads() {diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware.rs b/crates/openhuman-core/src/agent/tinyagents/middleware.rsindex c71f37d902..280be6072b 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware.rs@@ -34,7 +34,6 @@ mod failure_policy;mod fetched_site;mod loop_guards;mod memory_pack;-mod nudge_injector;mod packed_tool_route;mod repeated_failure;mod research_budget;diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/nudge_injector.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/nudge_injector.rsdeleted file mode 100644index db74c1cd74..0000000000--- a/crates/openhuman-core/src/agent/tinyagents/middleware/nudge_injector.rs+++ /dev/null@@ -1,63 +0,0 @@-//! Request-scoped delivery of `RepeatedToolFailureMiddleware` nudges.-//!-//! Split from `repeated_failure.rs` to stay under the Rust layout line limit.--use std::sync::{Arc, Mutex};--use async_trait::async_trait;--use tinyagents_harness::context::RunContext;-use tinyagents_harness::error::Result as TaResult;-use tinyagents_harness::middleware::{push_ephemeral_instruction, Middleware};-use tinyinference_llm::model::ModelRequest;--/// Appends queued `RepeatedToolFailureMiddleware` nudges to the next model-/// request, then forgets them. The request is built from a copy of the working-/// transcript, so nothing it adds is ever committed.-/// [`push_ephemeral_instruction`] places them: a tail system message, except on-/// a model that hoists system turns (DeepSeek), where one resets the prompt-/// cache (#6962), so the nudge rides the tail tool result.-pub(crate) struct PendingNudgeInjector {- pub(super) pending: Arc<Mutex<Vec<String>>>,-}--#[async_trait]-impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext> for PendingNudgeInjector {- fn name(&self) -> &str {- "pending_nudge_injector"- }-- // A prior middleware can request retry/stop control after a failed tool- // call. The queued correction still has to reach that retry request.- fn is_observer(&self) -> bool {- true- }-- async fn before_model(- &self,- ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,- _state: &(),- request: &mut ModelRequest,- ) -> TaResult<()> {- let nudges = self- .pending- .lock()- .map(|mut pending| std::mem::take(&mut *pending))- .unwrap_or_default();- if !nudges.is_empty() {- let hoists = ctx- .model_profile- .as_ref()- .is_some_and(|profile| profile.hoists_system_messages);- tracing::debug!(- count = nudges.len(),- hoists,- "[tinyagents::mw] request-scoped nudge(s) appended to the next model request"- );- for nudge in nudges {- push_ephemeral_instruction(request, nudge, ctx.model_profile.as_ref());- }- }- Ok(())- }-}diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rsindex c4c2345e3a..d409684ead 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs@@ -23,12 +23,12 @@ use super::loop_guards::{is_repeat_call_exempt, RECOVERABLE_NO_PROGRESS_FAILURE_THRESHOLD,RECOVERABLE_REPEAT_FAILURE_THRESHOLD,};-use tinyagents_harness::middleware::{EphemeralInstructionQueue, EphemeralInstructionMiddleware};pub(crate) use crate::inference::failure_copy::user_actionable_escalation;use crate::inference::failure_copy::{recoverable_identical_halt_summary, recoverable_no_progress_halt_summary,terminal_inference_failure_kind, terminal_inference_halt_summary,};+use tinyagents_harness::middleware::{EphemeralInstructionMiddleware, EphemeralInstructionQueue};use tinyinference_llm::failure::is_recoverable_failure_text as is_recoverable_tool_failure;/// `after_tool`: stop (or nudge) the run when tool calls keep failing with nodiff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rsindex 406d884bea..79b6cd948e 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs@@ -546,7 +546,11 @@ fn a_mistyped_file_path_is_a_correctable_call_not_a_missing_program() {/// Queue one validation/no-progress-style nudge the way a first shell timeout/// does, and return the middleware holding it.-async fn middleware_with_one_pending_nudge() -> RepeatedToolFailureMiddleware {+async fn middleware_with_one_pending_nudge() -> (+ RepeatedToolFailureMiddleware,+ tinyagents_harness::context::RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,+) {+ let mut run_ctx = ctx();let handle = SteeringHandle::allow_all();let slot = std::sync::Arc::new(std::sync::Mutex::new(None));let mw = RepeatedToolFailureMiddleware::new(handle, 3, slot);@@ -555,12 +559,12 @@ async fn middleware_with_one_pending_nudge() -> RepeatedToolFailureMiddleware {"shell",serde_json::json!({ "command": "whois a.io" }),);- mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();+ mw.before_tool(&mut run_ctx, &(), &mut call).await.unwrap();let mut result = failing_result("shell", "Command timed out after 60s and was killed");- mw.after_tool(&mut ctx(), &(), &invocation("sh-1", "shell"), &mut result)+ mw.after_tool(&mut run_ctx, &(), &invocation("sh-1", "shell"), &mut result).await.unwrap();- mw+ (mw, run_ctx)}fn nudge_request(leading: &TaMessage) -> ModelRequest {@@ -588,14 +592,13 @@ fn system_messages(request: &ModelRequest) -> usize {/// result instead, and the leading system message stays byte-identical.#[tokio::test]async fn nudges_for_a_hoisting_model_add_no_system_message() {- let mw = middleware_with_one_pending_nudge().await;+ let (mw, mut run_ctx) = middleware_with_one_pending_nudge().await;let injector = mw.nudge_injector();// The injector must remain in the before-model pass after a prior// middleware requests retry control, or the queued correction is lost.assert!(tinyagents_harness::middleware::Middleware::is_observer(&injector));- let mut run_ctx = ctx();run_ctx.model_profile = Some(tinyinference_llm::model::ModelProfile {hoists_system_messages: true,mid_conversation_system_messages: true,@@ -623,12 +626,12 @@ async fn nudges_for_a_hoisting_model_add_no_system_message() {/// Other models keep the tail system message the nudge always used.#[tokio::test]async fn nudges_for_other_models_stay_tail_system_messages() {- let mw = middleware_with_one_pending_nudge().await;+ let (mw, mut run_ctx) = middleware_with_one_pending_nudge().await;let leading = TaMessage::system("persona");let mut request = nudge_request(&leading);mw.nudge_injector()- .before_model(&mut ctx(), &(), &mut request)+ .before_model(&mut run_ctx, &(), &mut request).await.unwrap();