[PR #212] [MERGED] Universal agent tool support #4507

Closed
opened 2026-10-22 04:08:15 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/212
Author: @adunato
Created: 4/24/2026
Status: ✅ Merged
Merged: 4/28/2026
Merged by: @SpicyMarinara

Base: main ← Head: upstream-main


📝 Commits (10+)

  • 17f4939 docs: init HLD and implementation plan for CR002 universal_agent_tool_support
  • d70a806 feat: relocate and generalize agent tool resolution
  • f51226c feat: add debug logging for agent tool calls and results
  • dacd62a feat: improve agent-pipeline logging to show both batchable and tool-using agent names
  • 2bc2466 fix: consolidate spotify tool context flow
  • 6248b4b fix: guard invalid custom tool schemas
  • 9f386f4 fix: resolve spotify creds without active agent
  • 9277140 fix: resolve agent tool defs independently
  • b8daaa0 fix: enforce agent tool allowlists
  • 2479ffc fix: filter main generation tool calls

📊 Changes

5 files changed (+340 additions, -174 deletions)

View changed files

📝 packages/server/src/routes/generate.routes.ts (+275 -160)
📝 packages/server/src/services/agents/agent-executor.ts (+54 -1)
📝 packages/server/src/services/agents/agent-pipeline.ts (+1 -1)
📝 packages/server/src/services/tools/tool-executor.ts (+9 -12)
📝 packages/shared/src/types/agent.ts (+1 -0)

📄 Description

Closes #279

Resubmission of universal agent tool support #188 after clean up and addressing previous copilot feedback

CR002 Universal Agent Tool Support - Upstream PR Description

Why this change

Problem statement

The generation pipeline previously only attached function-calling support to the built-in Spotify agent. Other built-in and custom agents could have enabledTools configured, but they were still treated as text-only agents in the pipeline and executed as batchable.

This meant non-Spotify agents could not actually invoke tools during their turn, even when tool usage was configured for that agent.

Solution

This change generalizes agent tool support in generate.routes.ts.

When chat-level tools are enabled, the route now resolves tool definitions once, filters them per agent allowlist, and attaches toolContext to any resolved agent with active tools. This preserves chat-level tool gating while enabling both built-in and custom agents to use tools correctly.

What changed

Core changes

  • generate.routes.ts

    • moved tool definition and custom-tool resolution earlier in the request flow
    • removed the hardcoded Spotify-only tool assignment path
    • added universal per-agent toolContext attachment for resolved agents with allowed tools
    • kept chat-level tool enablement as the master gate for all tool use in the request
    • reused a single Spotify credential resolution path and only resolves/refershes Spotify credentials when Spotify tools are actually relevant to the request
    • added server-side filtering for main-generation tool calls so only allowed tools are executed
    • added server-side allowlist enforcement for agent tool calls
    • hardened custom tool registration by rejecting duplicate tool names and skipping invalid parameter schemas safely
  • agent-pipeline.ts

    • improved diagnostics so pipeline logs distinguish batchable agents from tool-using agents
  • agent-executor.ts

    • added [agent-tools] diagnostics for tool invocation and completion
    • gated raw args/results behind DEBUG_AGENTS=true
    • redacts and truncates debug payload logging

Validation

  • pnpm check
  • Manual verification completed

Manual verification notes

  • Custom-agent tool path:

    • configured a custom test agent with roll_dice enabled
    • confirmed the pipeline now reports the agent as tool-using instead of batchable
    • confirmed the agent successfully invoked roll_dice and received the JSON result for the follow-up model turn
  • Spotify regression check:

    • confirmed the Spotify DJ agent still executes through the tool loop
    • confirmed successful invocation of spotify_get_playlist_tracks, spotify_play, and spotify_set_volume
    • confirmed the earlier regression where Spotify tool execution stopped before playback is no longer present
  • Logging verification:

    • confirmed normal logs show tool invocation/completion with the [agent-tools] tag
    • confirmed debug mode (DEBUG_AGENTS=true) includes redacted/truncated tool args and results

Before / after evidence

Before:

[agent-pipeline] executeGroup: 1 batchable, 0 tool-using [ 'custom-test-agent' ]

After:

[agent-pipeline] executeGroup: 0 batchable, 1 tool-using { batch: [], tools: [ 'custom-test-agent' ] }
[agent-tools] custom-test-agent calling: roll_dice
[agent-tools] custom-test-agent roll_dice completed

Docs and release impact

  • No user-facing docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence

Not applicable.

Additional notes

  • This PR intentionally keeps chat-level tool enablement as the master switch.
  • Agent enabledTools determines the subset of tools an agent may use once tools are enabled for the chat.

Summary by CodeRabbit

  • Refactor
    • Unified tool resolution and execution for agents and main generation, with earlier Spotify credential refresh and per-agent tool permission enforcement
  • Bug Fixes
    • Skips invalid custom tools and prevents duplicate tool names across sources
  • Diagnostics
    • Safer tool-call logging with sensitive-data redaction and improved debug information for agent grouping and tool calls

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/212 **Author:** [@adunato](https://github.com/adunato) **Created:** 4/24/2026 **Status:** ✅ Merged **Merged:** 4/28/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `main` ← **Head:** `upstream-main` --- ### 📝 Commits (10+) - [`17f4939`](https://github.com/Pasta-Devs/Marinara-Engine/commit/17f4939c5031a54d6f5695239a5fe4407f8b6269) docs: init HLD and implementation plan for CR002 universal_agent_tool_support - [`d70a806`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d70a806762dcdde66f9cf6786e5f7adf366ae07e) feat: relocate and generalize agent tool resolution - [`f51226c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f51226cdbd966f1df49f9bac739b313b616bc737) feat: add debug logging for agent tool calls and results - [`dacd62a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/dacd62a4165441e065772eb30298a82b3b1da1a6) feat: improve agent-pipeline logging to show both batchable and tool-using agent names - [`2bc2466`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2bc24661a17d1088204dae872b4e3bef6e5b7f84) fix: consolidate spotify tool context flow - [`6248b4b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6248b4bbe73917e18e473e37867ec48af9c970b2) fix: guard invalid custom tool schemas - [`9f386f4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9f386f44d4d3329c45aa7bcc73ec5dff04cc5ee8) fix: resolve spotify creds without active agent - [`9277140`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9277140ca639978e116919c821cc276700184f04) fix: resolve agent tool defs independently - [`b8daaa0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b8daaa01e253e8921a6e297f6ea4483dfbd57d66) fix: enforce agent tool allowlists - [`2479ffc`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2479ffc3750f2af545adfa65b82d2ad4e3504a4e) fix: filter main generation tool calls ### 📊 Changes **5 files changed** (+340 additions, -174 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/generate.routes.ts` (+275 -160) 📝 `packages/server/src/services/agents/agent-executor.ts` (+54 -1) 📝 `packages/server/src/services/agents/agent-pipeline.ts` (+1 -1) 📝 `packages/server/src/services/tools/tool-executor.ts` (+9 -12) 📝 `packages/shared/src/types/agent.ts` (+1 -0) </details> ### 📄 Description Closes #279 Resubmission of universal agent tool support #188 after clean up and addressing previous copilot feedback # CR002 Universal Agent Tool Support - Upstream PR Description ## Why this change ### Problem statement The generation pipeline previously only attached function-calling support to the built-in Spotify agent. Other built-in and custom agents could have `enabledTools` configured, but they were still treated as text-only agents in the pipeline and executed as `batchable`. This meant non-Spotify agents could not actually invoke tools during their turn, even when tool usage was configured for that agent. ### Solution This change generalizes agent tool support in `generate.routes.ts`. When chat-level tools are enabled, the route now resolves tool definitions once, filters them per agent allowlist, and attaches `toolContext` to any resolved agent with active tools. This preserves chat-level tool gating while enabling both built-in and custom agents to use tools correctly. ## What changed ### Core changes - `generate.routes.ts` - moved tool definition and custom-tool resolution earlier in the request flow - removed the hardcoded Spotify-only tool assignment path - added universal per-agent `toolContext` attachment for resolved agents with allowed tools - kept chat-level tool enablement as the master gate for all tool use in the request - reused a single Spotify credential resolution path and only resolves/refershes Spotify credentials when Spotify tools are actually relevant to the request - added server-side filtering for main-generation tool calls so only allowed tools are executed - added server-side allowlist enforcement for agent tool calls - hardened custom tool registration by rejecting duplicate tool names and skipping invalid parameter schemas safely - `agent-pipeline.ts` - improved diagnostics so pipeline logs distinguish `batchable` agents from `tool-using` agents - `agent-executor.ts` - added `[agent-tools]` diagnostics for tool invocation and completion - gated raw args/results behind `DEBUG_AGENTS=true` - redacts and truncates debug payload logging ## Validation - [x] `pnpm check` - [x] Manual verification completed ### Manual verification notes - Custom-agent tool path: - configured a custom test agent with `roll_dice` enabled - confirmed the pipeline now reports the agent as `tool-using` instead of `batchable` - confirmed the agent successfully invoked `roll_dice` and received the JSON result for the follow-up model turn - Spotify regression check: - confirmed the Spotify DJ agent still executes through the tool loop - confirmed successful invocation of `spotify_get_playlist_tracks`, `spotify_play`, and `spotify_set_volume` - confirmed the earlier regression where Spotify tool execution stopped before playback is no longer present - Logging verification: - confirmed normal logs show tool invocation/completion with the `[agent-tools]` tag - confirmed debug mode (`DEBUG_AGENTS=true`) includes redacted/truncated tool args and results ### Before / after evidence Before: ```text [agent-pipeline] executeGroup: 1 batchable, 0 tool-using [ 'custom-test-agent' ] ``` After: ```text [agent-pipeline] executeGroup: 0 batchable, 1 tool-using { batch: [], tools: [ 'custom-test-agent' ] } [agent-tools] custom-test-agent calling: roll_dice [agent-tools] custom-test-agent roll_dice completed ``` ## Docs and release impact - [x] No user-facing docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence Not applicable. ## Additional notes - This PR intentionally keeps chat-level tool enablement as the master switch. - Agent `enabledTools` determines the subset of tools an agent may use once tools are enabled for the chat. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Unified tool resolution and execution for agents and main generation, with earlier Spotify credential refresh and per-agent tool permission enforcement * **Bug Fixes** * Skips invalid custom tools and prevents duplicate tool names across sources * **Diagnostics** * Safer tool-call logging with sensitive-data redaction and improved debug information for agent grouping and tool calls <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:08:15 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4507
No description provided.