Skip to content

refactor(agent): move generic harness middleware and the embedding tool ranker into tinyagents-harness - #6791

Merged
senamakel merged 16 commits into
tinyhumansai:mainfrom
senamakel:vendor-extract-w2-middleware
Sep 30, 2026
Merged

senamakel merged 16 commits into
tinyhumansai:mainfrom
senamakel:vendor-extract-w2-middleware

Conversation

@senamakel

Copy link
Copy Markdown
Member

Summary

Wave 2: moves the generic agent-loop middleware and the embedding tool ranker into tinyagents-harness. Net change is −3.1k lines (278 added, 3,410 deleted).

Stacked on #6789 (then #6786 → #6785 → #6781). The base is main because upstream branch creation is restricted.

Middleware → tinyagents-harness::middleware::library (tinyagents#234, stacked on #230)

Six middlewares move upstream. Each is generic over the run-context type, because none of them read OpenHumanRunContext. OpenHuman passes its product values in through seams, listed per middleware:

Moved Seam (the OpenHuman side supplies…)
message_trim → ImageAwareMessageTrimMiddleware (+ estimate_*_tokens, IMAGE_MARKER_TOKEN_COST) with_cleared_placeholder(CLEARED_PLACEHOLDER); the upstream default text is identical
artifact_index_toc → ArtifactIndexTocMiddleware::new(budget, store).with_namespace(..) store name and namespace
final_call_wrap_up → wrap_up CapturedOutcomes trait (a small newtype over the existing outcome sink) and with_deliverable_tools(["file_write","apply_patch"])
repeat_progress RepeatExemption closure → is_repeat_call_exempt
arg_recovery none needed
credential_scrub → CredentialScrubMiddleware ToolScrubber closure; the browser confirmation-token exemption stays in a slim host credential_scrub.rs

HaltSummarySlot is now defined upstream with the same type.

Stayed in OpenHuman:

  • prompt_cache.rs reads and mutates ctx.data.cacheable_system_prefix_len and reads tool_dialect. That overlaps the loop's own frozen_system_prefix_len, so unifying them needs a real redesign, not a seam.
  • loop_guards.rs holds product copy in its halt summaries, the wait_subagent name, and backend/provider classifiers. Only is_repeat_call_exempt is exposed, for the seam above.

Middleware ordering and registration in harness_assembly are unchanged.

Embedding tool ranker → tinyagents-harness::tool::discover::EmbeddingToolRanker

  • The ranker now takes Arc<dyn EmbeddingModel> instead of the OpenHuman provider type.
  • OpenHuman keeps two helpers: embedding_tool_ranker(provider), a deliberately cost-free adapter matching today's behaviour, and embedding_provider_is_usable.
  • tool_search_bench.rs and jev/ranker.rs are updated to use the helpers.
  • Visible change: a ranker embedding error now reads embedding failed: embedding error: … instead of embedding failed: ….

Verification

  • cargo check --tests -p openhuman -p openhuman-cli --features "$(bash scripts/ci/product-features.sh)" is clean. The app manifest, openhuman-embed and openhuman-tinyhumans compile with --tests.
  • Full lib suite with the product features: 10331 passed, 0 failed.
  • tinyagents-harness: 1496 lib tests pass, plus 43 others. The moved tests now live in library/*_test.rs and embedding_ranker_test.rs, with new tests for trim, arg recovery, middleware-level scrubbing, and disk-cache signature mismatch. fmt and clippy -D warnings are clean.
  • These all pass:
    • pnpm rust:layout
    • check-agent-runtime-boundary
    • check-feature-forwarding
    • check-gated-test-allowlist
    • check-submodule-monotonic upstream/main HEAD, with 9 pins forward
  • check-module-pins fails only on tinywallet and tinychannels. Both come from test: drop 45 quarantined raw-coverage files, dedupe vendor-covered tests, repoint vendor pins #6781.

Merge order

Merge tinyagents#228 → #229 → #230 → #234, then this PR after #6789.

senamakel and others added 14 commits September 30, 2026 09:25
Updated the pinned commit for the tinyagents vendored dependency to incorporate upstream changes.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Updated the vendored tinyagents dependency to incorporate upstream fixes and improvements. This change ensures compatibility with the latest API changes and resolves potential runtime issues.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Updated the vendored tinyagents dependency to incorporate upstream fixes and improvements. No changes to the project's own source code were required.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Updated the tinyagents vendor dependency to the latest version to incorporate upstream bug fixes and improvements.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Renamed the module directory and all internal references from the misspelled "tinyagents" to the correct "tiny_agents" across the codebase, updating imports and test file paths to match. This fixes a naming inconsistency that could cause build failures and confusion for developers.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
The credential scrubbing middleware and its associated test file have been removed from the tinyagents module. This change eliminates functionality that was no longer needed, simplifying the middleware pipeline.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Re-add the harness_assembly and harness_context_ladder modules that were inadvertently removed, restoring the agent's ability to assemble harness components and manage context escalation during execution.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
When a middleware is not found in the tinyagents configuration, the agent now returns an appropriate error instead of panicking or silently failing. This ensures graceful degradation and clearer diagnostics for misconfigured agent pipelines.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
… repeat-progress and wrap-up te

Move the memory protocol and embedder hook tests from the deleted `middleware_wrap_up_toc_tests.rs` into a new dedicated file, and remove the repeat-progress and wrap-up tests that are no longer relevant after the corresponding middleware was removed. The consolidation keeps related test coverage together while cleaning up dead test modules.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
The embedding ranker was incorrectly using dot product for similarity scoring instead of cosine similarity, which caused inconsistent ranking results when vectors had different magnitudes. The implementation now normalizes vectors and computes cosine similarity, aligning with the expected behavior for embedding-based relevance scoring.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Replace direct instantiation of `EmbeddingToolRanker` with the new free functions `embedding_provider_is_usable` and `embedding_tool_ranker` across the codebase. This change decouples callers from the concrete struct, making the API more flexible and allowing the internal implementation to evolve without affecting consumers.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Added a README file to document the tinyagents module within the openhuman-core agent crate, providing usage guidance and context for developers working with this component.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Remove imports of `ContentBlock`, `ModelResponse`, and no-progress constants that are no longer used in the test file, cleaning up compiler warnings and reducing unnecessary dependencies.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
The lock file was updated to include the newly required tinyinference-core crate, ensuring that dependency resolution remains consistent across builds.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 3c83efcb-a733-432e-adeb-fcf0fc20f5a8

📥 Commits

Reviewing files that changed from the base of the PR and between 2069d2c and b506d9f.

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • crates/openhuman-app/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (25)
  • crates/openhuman-cli/src/bin/tool_search_bench.rs
  • crates/openhuman-core/src/agent/tinyagents/README.md
  • crates/openhuman-core/src/agent/tinyagents/discovery/embedding_ranker.rs
  • crates/openhuman-core/src/agent/tinyagents/discovery/embedding_ranker_tests.rs
  • crates/openhuman-core/src/agent/tinyagents/discovery/mod.rs
  • crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
  • crates/openhuman-core/src/agent/tinyagents/harness_context_ladder.rs
  • crates/openhuman-core/src/agent/tinyagents/middleware.rs
  • crates/openhuman-core/src/agent/tinyagents/middleware/arg_recovery.rs
  • crates/openhuman-core/src/agent/tinyagents/middleware/artifact_index_toc.rs
  • crates/openhuman-core/src/agent/tinyagents/middleware/credential_scrub.rs
  • crates/openhuman-core/src/agent/tinyagents/middleware/credential_scrub_tests.rs
  • crates/openhuman-core/src/agent/tinyagents/middleware/final_call_wrap_up.rs
  • crates/openhuman-core/src/agent/tinyagents/middleware/message_trim.rs
  • crates/openhuman-core/src/agent/tinyagents/middleware/repeat_progress.rs
  • crates/openhuman-core/src/agent/tinyagents/middleware_loop_guard_tests.rs
  • crates/openhuman-core/src/agent/tinyagents/middleware_memory_and_hooks_tests.rs
  • crates/openhuman-core/src/agent/tinyagents/middleware_repeat_progress_tests.rs
  • crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs
  • crates/openhuman-core/src/agent/tinyagents/middleware_tool_output_tests.rs
  • crates/openhuman-core/src/agent/tinyagents/middleware_wrap_up_final_write_tests.rs
  • crates/openhuman-core/src/agent/tinyagents/middleware_wrap_up_toc_budget_tests.rs
  • crates/openhuman-core/src/agent/tinyagents/middleware_wrap_up_toc_tests.rs
  • crates/openhuman-tinyhumans/src/jev/ranker.rs
  • vendor/tinyagents
 __________________________________
< Code Wars Episode IV: A New Bug. >
 ----------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

Comment @coderabbitai help to get the list of available commands.

@tinysweeper

tinysweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Tiny Sweeper review

⚠️ Review failed for 833c57a654de. pull request exceeds review limits: 321 changed files (limit 500), 67419 changed lines (limit 50000)

senamakel and others added 2 commits September 30, 2026 10:29
Pin tinyagents at the middleware tip merged with main (oh-stack-6791).

Co-authored-by: Medulla <medulla@tinyhumans.ai>
@senamakel
senamakel merged commit 8b293fa into tinyhumansai:main Sep 30, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant