openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

feat(composio,agent): async sync + gated-tools surface + composio_enable_scope + force-delegate capability questions

Open sanil-23 opened this issue 6 months ago • 1 comments

Summary

  • composio_sync is now fire-and-forget: the RPC validates synchronously (connection_id / toolkit / provider), then tokio::spawn(provider.sync) and returns {status: "started", ...} immediately. UI is no longer pinned for the 30 s frontend RPC cap while the provider walks an entire prod inbox in-band. Per-source progress already flows via the existing openhuman.memory_sync_status_list poll (reads mem_tree_chunks directly so the spawned task is reflected in real time).
  • Gated-tools surface for the integrations agent: ConnectedIntegration gains gated_tools: Vec<GatedIntegrationTool> (no parameters field — LLM can't construct a call envelope for one). fetch_connected_integrations now partitions a toolkit's actions into visible/callable vs gated-by-pref. The integrations_agent prompt renders an "Additional capabilities behind a permission toggle" section so the agent can answer "do you support X?" with "yes but admin scope is off — want me to enable it?" instead of confabulating "no I can't".
  • New composio_enable_scope meta-tool: agent-callable (registered in all_composio_agent_tools), takes (toolkit, scope?), flips the per-toolkit composio-user-scopes KV row. Strong "ALWAYS ask the user for explicit consent first" wording in the description.
  • Orchestrator force-delegates capability questions to integrations_agent rather than answering from training-data priors (which were systematically wrong — confidently claimed Gmail had no bulk-delete when the toolkit ships GMAIL_BATCH_DELETE_MESSAGES).

Problem

Observed in production-mode use over a long debugging session:

  1. composio_sync consistently shows "sync failed" in the UI ~30 s in, but the server-side sync is healthy and continues. The frontend RPC .await cap is too tight for a real prod inbox — provider.sync walks all pages in-band and ingests every message synchronously inside the RPC handler. There is no good reason for the UI to block on it; per-source progress is already polled separately.
  2. Agent flatly denies capabilities the toolkit has — user asks "can you delete spam?", agent replies "nope, I can't delete or trash emails through the Gmail integration". Wrong: Gmail's Composio catalog ships GMAIL_BATCH_DELETE_MESSAGES, GMAIL_DELETE_THREAD, GMAIL_MOVE_TO_TRASH, etc. Two root causes — (a) admin-scoped tools are filtered out of the agent's tool list by default user pref ({read:true, write:true, admin:false}) AND filtered out of the prompt-side tools: field, so the agent has zero awareness they exist; (b) for the orchestrator agent, even when admin is on, the orchestrator's training-data prior about toolkit capabilities is unreliable — it answers "can you do X?" from priors rather than delegating to the agent that actually has the tool list.

Solution

Concern File(s) What
Sync hang composio/ops.rs:1012 tokio::spawn(provider.sync(...)) + return SyncOutcome{status:"started", finished_at_ms:0, ...} immediately. Validation (resolve client, lookup provider, lookup toolkit) stays synchronous so bad-request errors surface via the RPC envelope.
Agent unaware of gated capabilities agent/prompts/types.rs, composio/providers/mod.rs, composio/ops.rs, integrations_agent/prompt.rs New GatedIntegrationTool (no parameters field — descriptive only). New curated_scope_for(slug) helper. Producer (fetch_connected_integrations_uncached) partitions into tools + gated_tools. Integrations-agent prompt renders a "behind a permission toggle" section, including instructions on how to call composio_enable_scope with user consent.
Elevation path composio/tools.rs New ComposioEnableScopeTool (struct, impl Tool, registered in all_composio_agent_tools).
Orchestrator confabulation orchestrator/prompt.rs New "Capability questions about connected toolkits" subsection in the delegation guide that forbids prior-based refusals for connected toolkits and tells the orchestrator the only honest "no" comes back from a delegation that found the action neither in visible tools nor gated_tools.
Plumbing welcome/prompt.rs, harness/subagent_runner/ops.rs, harness/test_support_test.rs, composio/ops_test.rs, tools/orchestrator_tools.rs Update existing ConnectedIntegration { ... } literal sites to populate the new gated_tools field (defaults to Vec::new()).

Design choices worth flagging for reviewers:

  • Why a separate gated_tools field instead of inlining: the parameters: None distinction is load-bearing — without it the LLM can construct call envelopes for tools it can't actually invoke. Splitting at the type level enforces that the prompt-render path produces descriptive-only output for gated entries.
  • Why ComposioEnableScopeTool is a separate meta-tool rather than auto-elevation: granting Admin scope persists across sessions. Self-elevation without explicit user consent is a security boundary regression. The tool relies on the prompt contract today ("ALWAYS ask the user for explicit consent first") and is the right shape to wire into the wider tool-policy / approval-gate layer (#2149 / #2166 area) when that lands.
  • Why force-delegate capability questions vs. push tool data into the orchestrator prompt: orchestrator prompt-size is already a concern and most user questions about toolkits don't need a sub-agent round-trip. But for "can you do X?" / "does Y support Z?", the orchestrator's training-data prior is systematically a subset of the real catalog. One sub-agent hop is cheap; a confidently wrong refusal is not.

Submission Checklist

  • [x] N/A: tests deferred to a follow-up commit — see Validation Blocked below. The behavioural change is verified by partition-log evidence on a live workspace ([composio][scopes] integrations prompt action set toolkit=googledrive visible=14 gated=6, etc.) but unit-test additions for the partition logic, composio_enable_scope.execute(), and the orchestrator prompt-render change are pending. The PR is opened as DRAFT for this reason.
  • [x] N/A: diff coverage gate will not pass on this commit alone — same reason. Will land tests in follow-up before un-drafting.
  • [x] N/A: no behaviour-only feature ID change — the new gated_tools surface is an additive extension of the existing composio.connected_integrations capability; no new top-level feature row required.
  • [x] N/A: no matrix-tracked feature IDs touched (changes are agent-prompt / Composio infrastructure).
  • [x] No new external network dependencies — composio_enable_scope writes to the existing per-toolkit KV; composio_sync change is purely scheduling.
  • [x] N/A: no release-cut surface touched (no manual smoke checklist change needed).
  • [x] N/A: no linked issue — the changes were derived from a long-running production-mode debugging session, not a tracked ticket. Happy to file follow-up issues if reviewers prefer.

Impact

Runtime / platform: desktop, all platforms. No platform branches added or changed.

Performance: net positive. composio_sync no longer pins the UI thread; the orchestrator delegation cost (one extra sub-agent round-trip for capability questions) is bounded and only fires on questions that today produce confidently wrong refusals.

Migration / compatibility: schema-level — adding gated_tools to ConnectedIntegration is an additive Rust struct field; every internal constructor was updated to Vec::new() so behaviour is identical when no curated entries are pref-blocked. Backward-compatible.

Security: composio_enable_scope is the only privilege-changing surface added. Documented requirement: agent must ask for explicit user consent before invocation. No silent self-elevation. Wider tool-policy / approval-gate integration recommended as a follow-up.

Related

  • Closes:
  • Follow-up PR(s)/TODOs:
    • Unit tests for the gated_tools partition, ComposioEnableScopeTool.execute(), and the orchestrator force-delegate prompt section.
    • Wire composio_enable_scope into the tool-policy / approval-gate layer (#2149 / #2166 area) so the user-consent contract is enforced at runtime, not only via prompt instruction.

AI Authored PR Metadata (required for Codex/Linear PRs)

Linear Issue

  • Key: N/A
  • URL: N/A

Commit & Branch

  • Branch: feat/composio-agent-ux
  • Commit SHA: 0e5b042e

Validation Run

  • [x] N/A: pnpm --filter openhuman-app format:check not run — Windows working tree has the documented ~600-file CRLF/LF drift; format:check would rewrite unrelated files. Pre-push hook bypassed via --no-verify per the same documented pattern.
  • [x] N/A: pnpm typecheck not run — no TypeScript surface changed in this PR (Rust core only).
  • [x] Focused tests: existing prompt-builder tests in integrations_agent/prompt.rs, orchestrator/prompt.rs, welcome/prompt.rs were updated to populate the new gated_tools field on ConnectedIntegration literals; existing composio/ops_test.rs and tools/orchestrator_tools.rs test helpers similarly updated.
  • [x] Rust fmt/check: cargo check ran implicitly via pnpm dev:app:win rebuild — 0 errors. cargo fmt not explicitly run; will run in the follow-up that adds tests.
  • [x] N/A: Tauri fmt/check — no app/src-tauri/ Rust changes in this PR.

Validation Blocked

  • command: cargo fmt and unit-test additions for the new partition + meta-tool paths
  • error: n/a — not blocked technically; bundled with the test-coverage follow-up before un-drafting.
  • impact: PR is opened as DRAFT; reviewer feedback welcome on the architectural direction (esp. the gated_tools / enable_scope shape) before I invest in the test suite.

Behavior Changes

  • Intended behavior change:
    1. composio_sync RPC returns {status:"started"} immediately instead of awaiting full provider sync.
    2. Integrations agent now sees + describes pref-gated toolkit actions and knows the elevation procedure.
    3. New composio_enable_scope meta-tool flips per-toolkit user scopes (with prompt-enforced user-consent contract).
    4. Orchestrator delegates capability questions about connected toolkits to integrations_agent instead of confabulating from priors.
  • User-visible effect:
    • "Memory Sources" UI no longer shows "sync failed" within 30 s — shows progress updating in real time via the existing poll.
    • Asking the agent "can you bulk-delete spam from Gmail?" produces a real answer (yes, with the relevant tool slugs and an optional composio_enable_scope prompt) rather than a confidently wrong "no".

Parity Contract

  • Legacy behavior preserved:
    • composio_sync still returns a SyncOutcome (now with status:"started" / finished_at_ms:0 as sentinels for "spawned").
    • All existing ConnectedIntegration consumers still receive populated tools; the new gated_tools is additive and starts empty whenever no curated entries are pref-blocked.
    • The orchestrator's existing delegation tools (delegate_to_integrations_agent, etc.) are unchanged; the new subsection only adds behavioural guidance, no new tools.
  • Guard/fallback/dispatch parity checks: prompt-builder tests for welcome, orchestrator, integrations_agent were updated to populate the new field; they still assert the same prompt-text invariants as before (## Connected Integrations, delegate_to_integrations_agent, per-toolkit bullets).

Duplicate / Superseded PR Handling

  • Duplicate PR(s): none
  • Canonical PR: this one
  • Resolution: n/a

🤖 Generated with Claude Code

sanil-23 avatar May 20 '26 12:05 sanil-23

📝 Walkthrough

Walkthrough

Adds gated tools to ConnectedIntegration and GatedIntegrationTool type; composio splits visible vs gated actions and spawns provider.sync returning a “started” outcome; prompts, memory header, logging, providers, and tests updated to surface unlock guidance while keeping scope elevation UI-only.

Changes

Gated Tools Implementation

Layer / File(s) Summary
Gated tools data model
src/openhuman/agent/prompts/types.rs
Adds GatedIntegrationTool and gated_tools: Vec<GatedIntegrationTool> on ConnectedIntegration with docs explaining these actions are not directly invocable.
Provider scope lookup
src/openhuman/composio/providers/scope_lookup.rs, src/openhuman/composio/providers/mod.rs
Adds curated_scope_for(slug) and toolkit_has_scope(toolkit, scope) and re-exports them; includes tests ensuring gating behavior and case-insensitive toolkit handling.
Composio sync & action discovery
src/openhuman/composio/ops.rs, src/openhuman/composio/ops_test.rs
composio_sync validates inputs then spawns provider.sync as background task and returns immediate “started” SyncOutcome; discovery emits tools and gated_tools with required_scope and unlock_paths. Tests updated to poll spawned ingestion.
Composio tools: policy & logging
src/openhuman/composio/tools.rs, src/openhuman/composio/tools_tests.rs
Scope-elevation is UI-only (no agent-callable enable tool). scope_error_message now includes required scope and Connections UI unlock path. composio_execute gains richer dispatch/result logging; tests/messages adjusted.
Integrations agent prompt rendering
src/openhuman/agent/agents/integrations_agent/prompt.rs
When connected integrations have gated_tools, render an “Additional capabilities behind a permission toggle” section enumerating each gated tool name, description (fallback), required_scope, and unlock_paths.
Orchestrator & welcome prompts
src/openhuman/agent/agents/orchestrator/prompt.rs, src/openhuman/agent/agents/welcome/prompt.rs
Orchestrator prompt explicitly delegates capability and action questions to integrations_agent, requires consulting live per-toolkit catalogue (including gated_tools), and updates tests to include gated_tools in fixtures.
Cross-chat context header
src/openhuman/agent/harness/memory_context.rs, src/openhuman/agent/memory_loader.rs
Header changed from "[Cross-chat context]\n" to "[Cross-chat context — historical; capabilities may have changed since]\n" via CROSS_CHAT_HEADER; tests updated to assert canonical header.
Test fixture propagation & runner wiring
src/openhuman/agent/harness/subagent_runner/ops.rs, src/openhuman/agent/harness/test_support_test.rs, src/openhuman/tools/orchestrator_tools.rs, various tests
All test helpers and fixtures updated to populate gated_tools (typically empty vec). Runner spawn path now copies gated_tools from cached integration when refreshing visible tools.

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

working

Suggested reviewers

  • senamakel
  • graycyrus

🐰 A rabbit pens a tiny note,
Of gated tools and background mote—
Permissions shown, not called outright,
Spawned sync hums into the night—
Guide the user, shed some light!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.
Title check ✅ Passed The title clearly maps to the main changes: async sync (composio_sync now fire-and-forget), gated-tools surface (ConnectedIntegration gains gated_tools field), UI-only scope elevation (elevation path moved to UI), and force-delegate capability questions (orchestrator now delegates to integrations_agent).

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


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

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