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(tinyagents): extract nudge injector into its own module
Steven Enamakele65b7d14069f
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware.rs b/crates/openhuman-core/src/agent/tinyagents/middleware.rsindex e3f479a760..53625b029f 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware.rs@@ -32,6 +32,7 @@ mod embedder_hooks;mod fetched_site;mod loop_guards;mod memory_protocol;+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.rsnew file mode 100644index 0000000000..6805e3e5af--- /dev/null+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/nudge_injector.rs@@ -0,0 +1,59 @@+//! 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;++use super::repeated_failure::RepeatedToolFailureMiddleware;++/// 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"+ }++ 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 da633bd863..6ece2e8f32 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs@@ -9,9 +9,7 @@ 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, ToolInvocationIdentity,-};+use tinyagents_harness::middleware::{Middleware, ToolInvocationIdentity};use tinyagents_harness::no_progress::{ClassifiedFailure, ClassifiedFailureTracker, NoProgress, NoProgressTracker, ToolAttempt,};@@ -25,6 +23,7 @@ use super::loop_guards::{is_repeat_call_exempt, RECOVERABLE_NO_PROGRESS_FAILURE_THRESHOLD,RECOVERABLE_REPEAT_FAILURE_THRESHOLD,};+use super::nudge_injector::PendingNudgeInjector;pub(crate) use crate::inference::failure_copy::user_actionable_escalation;use crate::inference::failure_copy::{recoverable_identical_halt_summary, recoverable_no_progress_halt_summary,@@ -712,48 +711,3 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>Ok(())}}--/// 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 {- pending: Arc<Mutex<Vec<String>>>,-}--#[async_trait]-impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext> for PendingNudgeInjector {- fn name(&self) -> &str {- "pending_nudge_injector"- }-- 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(())- }-}