openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Thread tool call context through policy

Open vaddisrinivas opened this issue 6 months ago β€’ 3 comments

Refs #2132

Summary

  • Adds structured ToolCallContext to tool policy requests.
  • Threads session tool call metadata into policy checks before execution.
  • Extends focused policy/session coverage for the context fields.

Codex PR Checklist

  • [x] Issue URL: https://github.com/tinyhumansai/openhuman/issues/2132
  • [x] Branch: codex/oh-2132-tool-call-context
  • [x] Commit SHA: 2c87a4f7bdb975f6f9e3bce7bbaf4567b18b52df
  • [x] Files changed summary: src/openhuman/agent/tool_policy.rs adds the context shape; src/openhuman/agent/harness/session/turn.rs populates it for session tool calls; src/openhuman/agent/harness/session/turn_tests.rs asserts policy receives it.
  • [x] Validation commands run: cargo fmt --manifest-path Cargo.toml --all --check; cargo test --manifest-path Cargo.toml tool_policy; node scripts/check-pr-checklist.mjs /tmp/pr-body-2132.md.
  • [x] Validation commands blocked: pnpm pr:checklist /tmp/pr-body-2132.md blocked with zsh:1: command not found: pnpm; used the same checklist checker via node scripts/check-pr-checklist.mjs /tmp/pr-body-2132.md.
  • [x] Behavior change: Tool policies can now inspect structured tool call context before execution. No intended behavior change for tools or policies that ignore the new field.
  • [x] Duplicate/stale PR note: No existing PR found for vaddisrinivas:codex/oh-2132-tool-call-context or issue 2132 before opening this draft PR.

Summary by CodeRabbit

  • Refactor

    • Improved tool-invocation context tracking to include structured session, channel, agent, call and iteration metadata while keeping backward-compatible request fields.
    • Policy requests now carry richer provenance and mirror legacy identifiers.
  • Tests

    • Tightened tests to assert full context population and verify debug output redacts sensitive tool arguments and context fields.

Review Change Stack

vaddisrinivas avatar May 20 '26 11:05 vaddisrinivas

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 44a986a4-bd52-493e-820f-bbf932e09e9a

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 9200fd2ac6745f51ecbad7fe7f203066f151c78a and 4bd36a3c75776d165c5b19b1f950ee69baa520b8.

πŸ“’ Files selected for processing (2)
  • src/openhuman/agent/harness/session/turn.rs
  • src/openhuman/agent/harness/session/turn_tests.rs

πŸ“ Walkthrough

Walkthrough

A new ToolCallContext struct and ToolCallSource enum are introduced; ToolPolicyRequest gains a context: ToolCallContext and a new(...) constructor that mirrors key fields. Agent::execute_tool_call now builds ToolCallContext::session(...) and calls ToolPolicyRequest::new(...). Tests are updated to assert the populated request.context fields.

Changes

Tool call context refactoring

Layer / File(s) Summary
Context types and ToolPolicyRequest contract
src/openhuman/agent/tool_policy.rs
Adds ToolCallContext with session(...), ToolCallSource enum, extends ToolPolicyRequest to include context and provides ToolPolicyRequest::new(...); tests updated to construct requests with the new context and assert mirror fields and context.call_id/context.source.
Tool execution context integration and validation
src/openhuman/agent/harness/session/turn.rs, src/openhuman/agent/harness/session/turn_tests.rs
execute_tool_call imports ToolCallContext and constructs ToolCallContext::session(...), using ToolPolicyRequest::new(...) for policy checks. DenyCountingPolicy test assertions expanded to validate request.context fields (session_id, channel, agent_definition_id, call_id, iteration).

Sequence Diagram(s)

sequenceDiagram
  participant Agent as Agent::execute_tool_call
  participant Policy as ToolPolicy
  participant Executor as ToolExecutor
  Agent->>Policy: ToolPolicyRequest::new(tool_name, args, ToolCallContext::session(...))
  Policy->>Agent: allow / deny
  Agent->>Executor: execute tool call (if allowed)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • tinyhumansai/openhuman#2132: Proposes adding and threading ToolCallContext and ToolPolicyRequest::new into policy/execution, matching this PR's changes.

Possibly related PRs

Suggested labels

working

🐰 I hop through code with a tidy knack, Context in paw, I stitch the track, Calls now carry their session song, Policies read it clear and strong, Debug hides secrets all day long πŸ₯•

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title 'Thread tool call context through policy' accurately summarizes the main change: adding and threading ToolCallContext through tool policy requests across multiple files.
Docstring Coverage βœ… Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

coderabbitai[bot] avatar May 20 '26 11:05 coderabbitai[bot]

@vaddisrinivas unresolved review feedback from graycyrus β€” please address before we review.

M3gA-Mind avatar May 20 '26 19:05 M3gA-Mind

Thanks for the nudge. I addressed the graycyrus review threads inline in 9200fd2 and marked the fixed conversations resolved. Re-review welcome.

vaddisrinivas avatar May 20 '26 19:05 vaddisrinivas