Skip to content

Add generated tool wrapper abstraction#2333

Merged
graycyrus merged 4 commits into
tinyhumansai:mainfrom
vaddisrinivas:codex/oh-2133-generated-tools
May 22, 2026
Merged

Add generated tool wrapper abstraction#2333
graycyrus merged 4 commits into
tinyhumansai:mainfrom
vaddisrinivas:codex/oh-2133-generated-tools

Conversation

@vaddisrinivas

@vaddisrinivas vaddisrinivas commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a generic generated tool definition, adapter trait, and Tool wrapper.
  • Convert generated definitions into normal Tool trait objects after schema validation and adapter-id checks.
  • Register the module without adding any default generated bundle.

Refs #2133

Checklist

  • Issue URL: Support generated capability tools from trusted runtime bundles #2133
  • Branch: codex/oh-2133-generated-tools
  • Commit SHA: 6254c676b2a660c3a486c710a2d6a8092884dedc
  • Files changed: src/openhuman/tools/generated.rs, src/openhuman/tools/mod.rs
  • Validations run: cargo fmt --manifest-path Cargo.toml --all --check; cargo test --manifest-path Cargo.toml generated_tool; node scripts/check-pr-checklist.mjs /tmp/openhuman-2133-pr-body.md
  • Blocked validations: pnpm pr:checklist /tmp/openhuman-2133-pr-body.md blocked with zsh:1: command not found: pnpm; direct node checklist script passed
  • Behavior change: No intended default behavior change. Generated tools are only available to callers that construct them.
  • Duplicate/stale PR note: N/A, checked branch and Support generated capability tools from trusted runtime bundles #2133 PR searches; none found.

Summary by CodeRabbit

  • New Features

    • Added dynamic generation of tool wrappers from metadata and support for pluggable adapters to run them.
    • Exposed generated-tool capabilities for use across the tools surface.
  • Improvements

    • Stronger validation and error handling for generated tool definitions, including trimming/normalizing fields to avoid whitespace-only values.
  • Tests

    • Added unit tests covering normalization, validation, and adapter delegation.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds a new generated tools module with GeneratedToolDefinition, a GeneratedToolAdapter trait, and GeneratedTool which normalizes and validates definitions, enforces adapter-id matching, delegates execution to adapters, provides batch construction, and includes unit tests and module export.

Changes

Generated Tool Framework

Layer / File(s) Summary
Tool definition and adapter contracts
src/openhuman/tools/generated.rs
GeneratedToolDefinition struct holds metadata (name, description, parameters_schema, permission/category/scope, adapter_id) and GeneratedToolAdapter trait plus GeneratedTool wrapper are declared.
GeneratedTool construction and Tool impl
src/openhuman/tools/generated.rs
GeneratedTool::new normalizes (trim) incoming name/description/adapter_id, validates fields and parameters_schema via SchemaCleanr, enforces adapter.id() == definition.adapter_id, exposes definition() accessor, and implements Tool delegating execute to the adapter.
Batch creation and helpers
src/openhuman/tools/generated.rs
generated_tools_from_definitions builds boxed dyn Tool instances from definitions using a shared adapter; normalize_definition and validate_definition implement trimming and schema validation with anyhow mapping.
Tests and module export
src/openhuman/tools/generated.rs, src/openhuman/tools/mod.rs
mod.rs now publicly exposes the generated submodule. Unit tests verify adapter delegation/output, schema type retention, adapter-id mismatch rejection, blank/whitespace adapter_id rejection, and constructor-time normalization trimming name, description, and adapter_id.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant GeneratedTool
  participant SchemaCleanr
  participant GeneratedToolAdapter

  Caller->>GeneratedTool: new(definition, adapter)
  GeneratedTool->>SchemaCleanr: validate(definition.parameters_schema)
  SchemaCleanr-->>GeneratedTool: validation result
  GeneratedTool->>GeneratedToolAdapter: adapter.id() (verify matches definition.adapter_id)
  GeneratedTool-->>Caller: Result::Ok(GeneratedTool) or Err

  Caller->>GeneratedTool: execute(args)
  GeneratedTool->>GeneratedToolAdapter: execute(definition, args)
  GeneratedToolAdapter-->>GeneratedTool: ToolResult
  GeneratedTool-->>Caller: ToolResult
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit trims the edges with care,
Hops through schemas in crisp evening air,
Matches adapters, lines up the tune,
Tests applaud beneath the moon,
🐇✨ Generated tools hum in a rune.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add generated tool wrapper abstraction' directly describes the main change: introducing a new wrapper abstraction for generated tools with supporting definition and adapter infrastructure.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@vaddisrinivas vaddisrinivas marked this pull request as ready for review May 20, 2026 13:00
@vaddisrinivas vaddisrinivas requested a review from a team May 20, 2026 13:00
@coderabbitai coderabbitai Bot added the working A PR that is being worked on by the team. label May 20, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/openhuman/tools/generated.rs (1)

65-73: ⚡ Quick win

Add debug/trace diagnostics on validation and adapter-mismatch error paths.

These branches are key contract failures; lightweight structured logs would improve operability and debugging.

As per coding guidelines: “Use log / tracing at debug or trace level on … error paths … and any branch that is hard to infer from tests alone.”

Also applies to: 129-138

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openhuman/tools/generated.rs` around lines 65 - 73, The validation and
adapter-mismatch branches lack diagnostics; add lightweight structured
tracing/log statements around validate_definition and before the anyhow::bail in
the adapter check (and the similar branch at the other location) to record
context like definition.name, definition.adapter_id, and adapter.id(); use
tracing::debug! or tracing::trace! (or log::debug!) to emit these fields
immediately before returning the error so operators can correlate failures
without changing control flow.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/openhuman/tools/generated.rs`:
- Around line 129-139: The validate_definition function allows a blank or
whitespace adapter_id; update validate_definition to also trim and check
definition.adapter_id (e.g., let adapter_id = definition.adapter_id.trim()) and
call anyhow::bail! when it's empty (message like "generated tool `{name}`
adapter_id must be non-empty"), before validating parameters_schema so
GeneratedToolDefinition cannot pass with an empty adapter_id; keep the existing
name/description/schema checks and use the same error style as the other guards.

---

Nitpick comments:
In `@src/openhuman/tools/generated.rs`:
- Around line 65-73: The validation and adapter-mismatch branches lack
diagnostics; add lightweight structured tracing/log statements around
validate_definition and before the anyhow::bail in the adapter check (and the
similar branch at the other location) to record context like definition.name,
definition.adapter_id, and adapter.id(); use tracing::debug! or tracing::trace!
(or log::debug!) to emit these fields immediately before returning the error so
operators can correlate failures without changing control flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 532b008d-f2d3-46c6-89a0-82a98ed654ba

📥 Commits

Reviewing files that changed from the base of the PR and between ebd6457 and 6254c67.

📒 Files selected for processing (2)
  • src/openhuman/tools/generated.rs
  • src/openhuman/tools/mod.rs

Comment thread src/openhuman/tools/generated.rs
@vaddisrinivas vaddisrinivas changed the title [codex] Add generated tool wrapper abstraction Add generated tool wrapper abstraction May 20, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/openhuman/tools/generated.rs (1)

72-84: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Trim adapter_id consistently before matching.

validate_definition only trims adapter_id to reject blank values, but Line 72 still compares the raw string. " echo-adapter " now passes validation and then fails the adapter check even when the logical ID matches. Normalize once on construction, or compare against definition.adapter_id.trim() here, and add a padded-whitespace test next to the blank-id case.

Also applies to: 149-150

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openhuman/tools/generated.rs` around lines 72 - 84, Normalize
definition.adapter_id before comparisons: change code so adapter IDs are
compared using a trimmed value (either by trimming and storing adapter_id at
construction/validation in validate_definition, or by using
definition.adapter_id.trim() wherever compared against adapter.id()). Update the
comparison at the if statement that uses adapter.id() != definition.adapter_id
and the similar check around lines 149-150 to use the trimmed form, and add a
unit test that covers an adapter_id with surrounding whitespace (e.g., "
echo-adapter ") alongside the existing blank-id test to ensure padded whitespace
is accepted and matches correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/openhuman/tools/generated.rs`:
- Around line 72-84: Normalize definition.adapter_id before comparisons: change
code so adapter IDs are compared using a trimmed value (either by trimming and
storing adapter_id at construction/validation in validate_definition, or by
using definition.adapter_id.trim() wherever compared against adapter.id()).
Update the comparison at the if statement that uses adapter.id() !=
definition.adapter_id and the similar check around lines 149-150 to use the
trimmed form, and add a unit test that covers an adapter_id with surrounding
whitespace (e.g., " echo-adapter ") alongside the existing blank-id test to
ensure padded whitespace is accepted and matches correctly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 499eda29-08a4-474a-b1e4-9d06ffe01298

📥 Commits

Reviewing files that changed from the base of the PR and between 6254c67 and 154f316.

📒 Files selected for processing (1)
  • src/openhuman/tools/generated.rs

coderabbitai[bot]
coderabbitai Bot previously approved these changes May 20, 2026

@graycyrus graycyrus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice abstraction — the adapter pattern is clean, tests are solid, and the defensive validation is appreciated. One correctness issue to fix before this is good to go.

File Changes
src/openhuman/tools/generated.rs New: GeneratedToolDefinition, GeneratedToolAdapter trait, GeneratedTool wrapper, batch conversion, validation, tests
src/openhuman/tools/mod.rs Register generated module

Note on #2133 coverage: This PR delivers the abstraction layer (definition + adapter + wrapper). The remaining acceptance criteria — registry integration, visibility/whitelisting, and tool-inspection surfaces — presumably land in follow-up PRs. Worth tracking explicitly so nothing slips.

Comment thread src/openhuman/tools/generated.rs
@vaddisrinivas

Copy link
Copy Markdown
Contributor Author

Thanks for calling out the scope note. I fixed the correctness issue in b8076ed. For #2133 coverage: this PR is intentionally the abstraction layer only (Refs #2133, not closing it). The remaining acceptance criteria stay tracked on #2133 / follow-up PRs for normal agent-path registration, visibility/whitelisting, and tool-inspection surfaces.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/openhuman/tools/generated.rs (1)

142-146: 💤 Low value

Optional: validate_definition now contains redundant .trim() calls.

Since normalize_definition is always invoked before validate_definition in the only caller (GeneratedTool::new), the .trim() calls inside validate_definition (lines 149, 153, 156) are now redundant — they operate on already-trimmed strings. You could simplify the empty-checks to definition.name.is_empty() / definition.description.is_empty() / definition.adapter_id.is_empty() for clarity, or keep the trims as a defensive belt-and-braces if validate_definition may be reused independently in the future. Not blocking.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openhuman/tools/generated.rs` around lines 142 - 146, The
validate_definition function currently calls .trim() on fields that have already
been normalized by normalize_definition, so update validate_definition to remove
the redundant .trim() calls and use simple empty checks (e.g.,
definition.name.is_empty(), definition.description.is_empty(),
definition.adapter_id.is_empty()); locate validate_definition and its caller
GeneratedTool::new to confirm normalize_definition is still invoked first and
ensure behavior remains unchanged (or keep trims if you prefer to retain
defensive checks).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/openhuman/tools/generated.rs`:
- Around line 142-146: The validate_definition function currently calls .trim()
on fields that have already been normalized by normalize_definition, so update
validate_definition to remove the redundant .trim() calls and use simple empty
checks (e.g., definition.name.is_empty(), definition.description.is_empty(),
definition.adapter_id.is_empty()); locate validate_definition and its caller
GeneratedTool::new to confirm normalize_definition is still invoked first and
ensure behavior remains unchanged (or keep trims if you prefer to retain
defensive checks).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f0e3da56-a3c6-4c1b-aa37-4278e92be81d

📥 Commits

Reviewing files that changed from the base of the PR and between 154f316 and b8076ed.

📒 Files selected for processing (1)
  • src/openhuman/tools/generated.rs

@vaddisrinivas

Copy link
Copy Markdown
Contributor Author

@graycyrus Thanks again for the review. I addressed the normalization issue in b8076ed and resolved the thread; current checks are green. Could you please take another look when you have a chance?

@vaddisrinivas vaddisrinivas requested a review from graycyrus May 21, 2026 19:48

@graycyrus graycyrus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continuation review — previous changes addressed ✓

The [major] whitespace normalization finding from the prior review is resolved. Commit b8076ed adds normalize_definition() which trims name, description, and adapter_id before validation and storage — clean approach, and the new generated_tool_normalizes_definition_fields test covers it well.

No new issues found in the latest commit. Code is clean — well-structured abstraction with solid validation and good test coverage.

@graycyrus graycyrus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, nice work!

@graycyrus graycyrus merged commit 80b9207 into tinyhumansai:main May 22, 2026
29 checks passed
CodeGhost21 pushed a commit to CodeGhost21/openhuman that referenced this pull request May 22, 2026
senamakel pushed a commit to aqilaziz/openhuman that referenced this pull request May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

working A PR that is being worked on by the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants