Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

Let TinyAgents own streamed narration cutoff

Steven Enamakel42bd423d99a5
diff --git a/crates/openhuman-core/src/agent/session_host/driver.rs b/crates/openhuman-core/src/agent/session_host/driver.rs
index 5e3606a7c4..e514ed3cc3 100644
--- a/crates/openhuman-core/src/agent/session_host/driver.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver.rs
@@ -512,7 +512,9 @@ fn driver_error_with_snapshot(
let history = guard.messages[..accepted_end].to_vec();
let unanswered =
crate::agent::tinyagents::render_unanswered_steps(&guard.messages[accepted_end..]);
- let display = if error.contains(crate::agent::tinyagents::middleware::STREAM_STALL_ERROR) {
+ let display = if error
+ .contains(&tinyagents_harness::TinyAgentsError::GenerationStalled.to_string())
+ {
// The model's streamed narration was stopped before it could repeat
// indefinitely. Preserve the completed tools as a useful, bounded
// partial rather than showing only the failed model's process text.
diff --git a/crates/openhuman-core/src/agent/session_host/driver_tests.rs b/crates/openhuman-core/src/agent/session_host/driver_tests.rs
index e31b44b6cb..af235f8f6c 100644
--- a/crates/openhuman-core/src/agent/session_host/driver_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver_tests.rs
@@ -59,7 +59,7 @@ fn stalled_model_stream_reports_completed_evidence_instead_of_its_narration() {
},
));
let failure = driver_error_with_snapshot(
- crate::agent::tinyagents::middleware::STREAM_STALL_ERROR,
+ tinyagents_harness::TinyAgentsError::GenerationStalled,
&snapshot,
&sidecar(),
std::time::Duration::from_millis(1),
diff --git a/crates/openhuman-core/src/agent/tinyagents/README.md b/crates/openhuman-core/src/agent/tinyagents/README.md
index 1532f0df70..bc0faa1bc9 100644
--- a/crates/openhuman-core/src/agent/tinyagents/README.md
+++ b/crates/openhuman-core/src/agent/tinyagents/README.md
@@ -8,6 +8,7 @@ The **adapter seam** between OpenHuman and the vendored [`tinyagents`](../../../
- Convert between OpenHuman and crate types: tiered `ChatModel` bundles from `(role, config)` (`turn_models.rs`, `model.rs`), direct TinyTools/TinyInference tool declarations at their consumers, and `ChatMessage`/`ConversationMessage` ↔ crate `Message` via `crate::agent::message_convert`.
- Enforce cross-cutting policy as harness middleware: approval/security gating, tool policy and CLI/RPC-only denial, cost budgets, context compaction/summarization, credential scrubbing, malformed-argument recovery, and the repeated-tool-failure circuit breaker (`middleware*.rs`).
- Route workloads to model tiers and record the resolved provider/model for audit (`routes.rs`, canonical TinyInference response metadata).
+- Let TinyAgents stop repetitive visible model streams in its agent loop; the OpenHuman session driver turns `GenerationStalled` into a bounded partial containing completed tool evidence.
- Make turns durable and replayable: a JSONL event journal plus status store (`journal.rs`), a startup sweep for orphaned runs (`reaper.rs`), and a read-only RPC surface over both (`replay/`).
- Provide graph-layer helpers for multi-stage sub-agent orchestration (`orchestration.rs`, `delegation.rs`) and expose graph structure for debugging (`topology.rs`).
- Host adapters (`host/`) for the crate's ten host-capability traits. Not yet wired into the live turn path; see [Host adapters](#host-adapters) below.
@@ -31,7 +32,6 @@ The **adapter seam** between OpenHuman and the vendored [`tinyagents`](../../../
| `reaper.rs` | `reap_orphaned_runs`: startup sweep that marks non-terminal runs `Cancelled` in the durable status store. The only writer over the status seam that `replay/` reads. |
| `middleware.rs` + `middleware/` | The named OpenHuman middleware stack. `turn_context.rs`: `TurnContextMiddleware` (bundles config and installs the enabled hooks), `TranscriptSnapshotMiddleware`/`TranscriptSnapshotSink`, `HandoffConfig`/`HandoffMiddleware` (oversized sub-agent results stashed for `extract_from_result`). `prompt_cache.rs`: `PromptCacheSegmentMiddleware`. `tool_output.rs`: `ToolOutputMiddleware` (per-result byte cap and optional payload summarizer). `approval.rs`: `ApprovalSecurityMiddleware`. `cli_rpc_only.rs`: `CliRpcOnlyMiddleware`. `tool_policy.rs`: the `ToolPolicyMiddleware` struct and impl (records blocks into `crate::tools::registry::denials`). `tool_outcome_capture.rs`: `ToolOutcomeCaptureMiddleware`. `embedder_hooks.rs`: `EmbedderToolHooksMiddleware`. `arg_recovery.rs`: `ArgRecoveryMiddleware`. `memory_protocol.rs`: `MemoryProtocolMiddleware`. `cost_budget.rs`: `CostBudgetMiddleware`. `repeated_failure.rs`: `RepeatedToolFailureMiddleware`. `loop_guards.rs`: `TerminalInferenceFailure`. `repeat_progress.rs`: `RepeatProgressMiddleware` (adjacent-repeat streaks plus a run-wide `(call, result)` recurrence ledger) and `RepeatEvictionObserver` (registered last; resets the ledger when compaction evicts a recorded result, #6275). `message_trim.rs`: `ImageAwareMessageTrimMiddleware`. `final_call_wrap_up.rs`: `FinalCallWrapUpMiddleware` (on the last permitted model call it withdraws the belt and asks for the conclusion; on the one before it, narrows the belt to `DELIVERABLE_TOOLS` so a turn whose product is a file can still write it). `artifact_index_toc.rs`: `ArtifactIndexTocMiddleware` (issue #6014). `credential_scrub.rs`: `CredentialScrubMiddleware` (issue #4453). |
| `middleware/research_budget.rs` | Forces a top-level direct web research turn to answer after eight completed search or fetch calls. |
-| `middleware/stream_stall.rs` | Stops repeated streamed narration before it can continue indefinitely. |
| `model.rs` | Helpers and wrappers over native crate `ChatModel` values: message/response translation, usage merging, stream-delta forwarding, `MaxTokensModel`, `ProfileOverrideModel`. |
| `tools.rs` | `CanonicalSharedToolAdapter`: resolves an OpenHuman shared tool registry and forwards the canonical `tinytools::Tool` contract; `EarlyExitHook` pauses successful `ask_user_clarification`-style calls. |
| `routes.rs` | `WORKLOAD_ROUTE_TIERS` (the tier inventory projected into the model registry), `RequiredCapabilitiesMiddleware`, `FallbackObserverMiddleware`, `UsageCarryMiddleware`, and the per-model fallback policy. |
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
index 65b503128c..4fc630343b 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
@@ -560,8 +560,6 @@ pub(super) fn assemble_turn_harness(
if subagent_scope.is_none() {
harness.push_middleware(Arc::new(middleware::ResearchBudgetMiddleware::new()));
}
- harness.push_middleware(Arc::new(middleware::StreamStallMiddleware::new()));
-
// SDK-owned tool-policy projection (issue #4249 / tinyagents-full-migration
// 01.1). Keep this narrow for now: enforce sandbox requirements declared by
// adapter policies without enabling classification/approval/result-byte
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware.rs b/crates/openhuman-core/src/agent/tinyagents/middleware.rs
index 482885da47..d5c4ace231 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware.rs
@@ -40,7 +40,6 @@ mod prompt_cache;
mod repeat_progress;
mod repeated_failure;
mod research_budget;
-mod stream_stall;
mod tool_exposure;
mod tool_outcome_capture;
mod tool_output;
@@ -62,7 +61,6 @@ pub(crate) use prompt_cache::PromptCacheSegmentMiddleware;
pub(crate) use repeat_progress::RepeatProgressMiddleware;
pub(crate) use repeated_failure::RepeatedToolFailureMiddleware;
pub(crate) use research_budget::ResearchBudgetMiddleware;
-pub(crate) use stream_stall::{StreamStallMiddleware, STREAM_STALL_ERROR};
pub(crate) use tool_exposure::OpenHumanToolExposureShadowMiddleware;
pub(crate) use tool_outcome_capture::ToolOutcomeCaptureMiddleware;
pub(crate) use tool_policy::ToolPolicyMiddleware;
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/stream_stall.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/stream_stall.rs
deleted file mode 100644
index ba9cdba1c1..0000000000
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/stream_stall.rs
+++ /dev/null
@@ -1,56 +0,0 @@
-//! Abort a provider stream whose visible text has become repetitive narration.
-
-use std::sync::Mutex;
-
-use async_trait::async_trait;
-use tinyagents_harness::context::RunContext;
-use tinyagents_harness::error::{Result as TaResult, TinyAgentsError};
-use tinyagents_harness::middleware::Middleware;
-use tinyagents_harness::no_progress::StreamTextStallDetector;
-use tinyinference_llm::model::ModelDelta;
-
-use crate::agent::tinyagents::host::OpenHumanRunContext;
-
-pub(crate) const STREAM_STALL_ERROR: &str = "streamed response stalled on repeated narration";
-
-#[derive(Default)]
-pub(crate) struct StreamStallMiddleware {
- current: Mutex<(String, StreamTextStallDetector)>,
-}
-
-impl StreamStallMiddleware {
- pub(crate) fn new() -> Self {
- Self::default()
- }
-}
-
-#[async_trait]
-impl Middleware<(), OpenHumanRunContext> for StreamStallMiddleware {
- fn name(&self) -> &str {
- "stream_stall"
- }
-
- async fn on_model_delta(
- &self,
- _ctx: &mut RunContext<OpenHumanRunContext>,
- _state: &(),
- delta: &mut ModelDelta,
- ) -> TaResult<()> {
- let Ok(mut current) = self.current.lock() else {
- return Ok(());
- };
- if current.0 != delta.call_id {
- current.0.clone_from(&delta.call_id);
- current.1.reset();
- }
- if delta.tool_call.is_some() {
- current.1.reset();
- return Ok(());
- }
- if current.1.observe(&delta.content) {
- tracing::warn!("[tinyagents::mw] stopped a repetitive model text stream");
- return Err(TinyAgentsError::Middleware(STREAM_STALL_ERROR.to_string()));
- }
- Ok(())
- }
-}
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_stream_stall_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_stream_stall_tests.rs
deleted file mode 100644
index c660d4b560..0000000000
--- a/crates/openhuman-core/src/agent/tinyagents/middleware_stream_stall_tests.rs
+++ /dev/null
@@ -1,63 +0,0 @@
-use super::*;
-
-#[tokio::test]
-async fn repetitive_stream_is_stopped_before_it_reaches_the_ui_indefinitely() {
- let mw = StreamStallMiddleware::new();
- let mut run = ctx();
- let mut stopped = false;
- for i in 0..12 {
- let mut delta = tinyinference_llm::model::ModelDelta {
- call_id: "jev-research".to_string(),
- content: format!("Let me check another page number {i} before answering the user. "),
- reasoning: String::new(),
- tool_call: None,
- };
- if mw.on_model_delta(&mut run, &(), &mut delta).await.is_err() {
- stopped = true;
- break;
- }
- }
- assert!(stopped);
-}
-
-#[tokio::test]
-async fn tool_progress_and_a_new_model_call_start_fresh_windows() {
- let mw = StreamStallMiddleware::new();
- let mut run = ctx();
- for call_id in ["first-call", "second-call"] {
- for i in 0..7 {
- let mut delta = tinyinference_llm::model::ModelDelta {
- call_id: call_id.to_string(),
- content: format!(
- "Let me check source number {i} before answering the user's request. "
- ),
- reasoning: String::new(),
- tool_call: None,
- };
- mw.on_model_delta(&mut run, &(), &mut delta).await.unwrap();
- }
- }
- let mut tool_delta = tinyinference_llm::model::ModelDelta {
- call_id: "second-call".to_string(),
- content: String::new(),
- reasoning: String::new(),
- tool_call: Some(tinyinference_llm::tool::ToolDelta {
- call_id: "fetch-1".to_string(),
- content: String::new(),
- tool_name: Some("web_fetch".to_string()),
- content_index: None,
- }),
- };
- mw.on_model_delta(&mut run, &(), &mut tool_delta)
- .await
- .unwrap();
- for i in 0..7 {
- let mut delta = tinyinference_llm::model::ModelDelta {
- call_id: "second-call".to_string(),
- content: format!("Let me inspect result number {i} before answering the user. "),
- reasoning: String::new(),
- tool_call: None,
- };
- mw.on_model_delta(&mut run, &(), &mut delta).await.unwrap();
- }
-}
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs
index d6c830960d..8277de3f48 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs
@@ -490,8 +490,6 @@ mod repeat_progress_tests;
#[path = "middleware_research_budget_tests.rs"]
mod research_budget_tests;
-#[path = "middleware_stream_stall_tests.rs"]
-mod stream_stall_tests;
#[path = "middleware_tool_output_artifact_tests.rs"]
mod tool_output_artifact_tests;
#[path = "middleware_tool_output_tests.rs"]
diff --git a/vendor/tinyagents b/vendor/tinyagents
index 981e9fb9e2..ad9762f859 160000
--- a/vendor/tinyagents
+++ b/vendor/tinyagents
@@ -1 +1 @@
-Subproject commit 981e9fb9e238da5f869bdc2b76b6a3ce848eee58
+Subproject commit ad9762f8596407394dd2baeb18cc728ee99102b4