Skip to content

fix(agent): refresh delegate_{toolkit} tools on first turn for web channel#1666

Closed
graycyrus wants to merge 1 commit into
tinyhumansai:mainfrom
graycyrus:fix/1659-delegate-toolkit-sync-builder
Closed

fix(agent): refresh delegate_{toolkit} tools on first turn for web channel#1666
graycyrus wants to merge 1 commit into
tinyhumansai:mainfrom
graycyrus:fix/1659-delegate-toolkit-sync-builder

Conversation

@graycyrus
Copy link
Copy Markdown
Contributor

Summary

  • Adds refresh_delegation_tools() on Agent, called after fetch_connected_integrations() on the first turn — re-synthesises skill-delegation tools (delegate_gmail, delegate_notion, …) with the live integrations list and merges them into the tool schema before the system prompt is built
  • Adds base_definition_id field to Agent to preserve the original definition ID through the web channel's set_agent_definition_name() mangling ("orchestrator""orchestrator_thread-6ad...")
  • Updates the &[] comment at the collect_orchestrator_tools call sites to document the refresh contract

Root cause

PR #1314 removed spawn_subagent from the orchestrator's allowed tools and rewrote the integrations prompt to advertise delegate_{toolkit} tools. The synchronous builder (builder.rs) passes &[] for connected integrations (can't call async Composio API), so zero skill-delegation tools are registered. Meanwhile fetch_connected_integrations() populates the prompt correctly — the model sees delegate_gmail in prose but can't call it, falling through to delegate_tools_agent which refuses.

Changes

File Change
types.rs base_definition_id field on Agent + AgentBuilder
builder.rs Wire base_definition_id, update &[] comments
turn.rs refresh_delegation_tools() method + call on first turn
runtime.rs base_definition_id() accessor
tests.rs 3 tests: populates tools, noop when empty, no duplicates

Test plan

  • refresh_delegation_tools_populates_skill_tools — connected gmail + github → delegate_gmail and delegate_github appear in tool schema
  • refresh_delegation_tools_noop_when_no_integrations — empty integrations = no-op
  • refresh_delegation_tools_skips_already_registered — calling twice doesn't duplicate tools
  • cargo check (core + Tauri shell) passes
  • cargo test — 6566 passed, 1 pre-existing failure (unrelated config test)
  • cargo fmt --check passes
  • pnpm typecheck / pnpm lint / pnpm format:check pass

Closes #1659

…nnel registers them

The synchronous agent builder passes `&[]` for connected_integrations to
`collect_orchestrator_tools()` because it cannot call the async Composio
fetcher. After PR tinyhumansai#1314 removed `spawn_subagent` and rewrote the prompt
to advertise `delegate_{toolkit}` tools, the web/Tauri channel's tool
schema diverged from the prompt — the model sees `delegate_gmail` in
prose but cannot call it.

Add `refresh_delegation_tools()` on `Agent`, called immediately after
`fetch_connected_integrations()` on the first turn. It re-synthesises
skill-delegation tools with the live integrations list and merges them
into `tools`, `tool_specs`, `visible_tool_names`, and
`visible_tool_specs` before `build_system_prompt()` runs.

Also adds `base_definition_id` to `Agent` so the original definition ID
survives the web channel's `set_agent_definition_name()` mangling
(e.g. `"orchestrator"` → `"orchestrator_thread-6ad..."`).

Closes tinyhumansai#1659
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ed57acd2-fffb-4b3f-9ba3-9cade33c9105

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

@senamakel
Copy link
Copy Markdown
Member

this is kidna fixed now in #1670

@senamakel senamakel closed this May 13, 2026
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.

Orchestrator's delegate_{toolkit} contract from PR #1314 broken on web channel — model emits delegate_gmail, runtime resolves to delegate_tools_agent

2 participants