[GH-ISSUE #2994] [Issue]: Tool-using built-ins (lorebook-keeper, knowledge-retrieval, expression, combat) run with no tools in main generation but get them on retry #1568

Closed
opened 2026-10-21 05:39:20 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2994

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong
Built-in agents enabled purely via the chat agent picker (never opened/saved in the full Agent Editor) run WITHOUT their default tools during normal generation. Lorebook-keeper and knowledge-retrieval lose search_lorebook, expression loses set_expression, combat loses roll_dice. The retry path re-injects the defaults, so the SAME agent behaves differently on retry vs normal generation — a visible capability loss and inconsistency (e.g. the lorebook-keeper can still write but can no longer look up existing entries before writing).

How to reproduce (try it yourself)

  1. In a chat, enable the Lorebook Keeper (or Knowledge Retrieval / Expression) agent purely via the chat agent picker, without ever opening it in the Agent Editor and pressing Save.
  2. Send a message so the agent runs.
  3. Send more messages: on each main generation the agent resolves with no enabledTools, so its default tool is not provided.
  4. Trigger "retry agents" on a message.

You'll see: on retry the default tool is re-added, so the agent behaves differently than on normal generation.
Expected: the agent has its default tools on both paths, exactly as it does when configured through the editor.

Where it is
Root cause (fix site): packages/server/src/services/generation/agent-resolution.ts:281-290 (enabledConfigs branch) AND :400-409 (builtInFallbacks branch) — both only inject DEFAULT_AGENT_TOOLS for spotify. Retry path that DOES re-inject for all built-ins: packages/server/src/routes/generate/retry-agents-route.ts:207-219 (applyDefaultBuiltInAgentTools). Runtime gate that makes the omission observable: packages/server/src/services/generation/tool-resolution-runtime.ts:689 (if (agentEnabledNames.length === 0) continue;). Contributing: packages/server/src/services/storage/agents.storage.ts:167 (ensureBuiltinConfig seeds no enabledTools) vs packages/server/src/routes/agents.routes.ts:128-131 (which adds them).

What's happening
getDefaultBuiltInAgentSettings() intentionally omits enabledTools; only the route/editor path layers DEFAULT_AGENT_TOOLS on top. Both main-generation resolution branches only re-inject tools for spotify, so tool-using built-ins materialized or fallback-resolved without going through the editor run tool-less. The runtime gate then skips building any tool context when enabledTools is empty.

Suggested fix
Fix the main-generation resolver so it matches the retry path for ALL built-ins, covering both the persisted (enabledConfigs) and first-generation (builtInFallbacks) paths, using !Array.isArray semantics so an explicit empty enabledTools (user removed all tools) is preserved, and excluding spotify (its provider-aware block is untouched).

After the spotify block at line 290 (enabledConfigs loop):

    if (
      cfg.type !== "spotify" &&
      BUILT_IN_AGENTS.some((agent) => agent.id === cfg.type) &&
      !Array.isArray(settings.enabledTools) &&
      (DEFAULT_AGENT_TOOLS[cfg.type as string]?.length ?? 0) > 0
    ) {
      settings.enabledTools = [...DEFAULT_AGENT_TOOLS[cfg.type as string]!];
    }

After the spotify block at line 409 (builtInFallbacks loop):

    if (
      builtIn.id !== "spotify" &&
      !Array.isArray(builtInSettings.enabledTools) &&
      (DEFAULT_AGENT_TOOLS[builtIn.id]?.length ?? 0) > 0
    ) {
      builtInSettings.enabledTools = [...DEFAULT_AGENT_TOOLS[builtIn.id]!];
    }

(BUILT_IN_AGENTS and DEFAULT_AGENT_TOOLS are already imported in agent-resolution.ts.) This also re-injects defaults for already-persisted tool-less rows. Regression avoided: patching only ensureBuiltinConfig (the suggested alt) is INSUFFICIENT — it does not fix the first-generation builtInFallbacks path (which runs before any DB row exists) nor existing tool-less rows. And the !Array.isArray check (not the spotify block's length === 0 predicate) is required so a user who deliberately removed all tools in the editor doesn't get them silently re-enabled. Optionally also seed enabledTools in ensureBuiltinConfig for consistency, but it is not sufficient alone.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2994 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** Built-in agents enabled purely via the chat agent picker (never opened/saved in the full Agent Editor) run WITHOUT their default tools during normal generation. Lorebook-keeper and knowledge-retrieval lose `search_lorebook`, expression loses `set_expression`, combat loses `roll_dice`. The retry path re-injects the defaults, so the SAME agent behaves differently on retry vs normal generation — a visible capability loss and inconsistency (e.g. the lorebook-keeper can still write but can no longer look up existing entries before writing). **How to reproduce (try it yourself)** 1. In a chat, enable the Lorebook Keeper (or Knowledge Retrieval / Expression) agent purely via the chat agent picker, without ever opening it in the Agent Editor and pressing Save. 2. Send a message so the agent runs. 3. Send more messages: on each main generation the agent resolves with no enabledTools, so its default tool is not provided. 4. Trigger "retry agents" on a message. You'll see: on retry the default tool is re-added, so the agent behaves differently than on normal generation. Expected: the agent has its default tools on both paths, exactly as it does when configured through the editor. **Where it is** Root cause (fix site): `packages/server/src/services/generation/agent-resolution.ts:281-290` (enabledConfigs branch) AND `:400-409` (builtInFallbacks branch) — both only inject DEFAULT_AGENT_TOOLS for spotify. Retry path that DOES re-inject for all built-ins: `packages/server/src/routes/generate/retry-agents-route.ts:207-219` (`applyDefaultBuiltInAgentTools`). Runtime gate that makes the omission observable: `packages/server/src/services/generation/tool-resolution-runtime.ts:689` (`if (agentEnabledNames.length === 0) continue;`). Contributing: `packages/server/src/services/storage/agents.storage.ts:167` (`ensureBuiltinConfig` seeds no enabledTools) vs `packages/server/src/routes/agents.routes.ts:128-131` (which adds them). **What's happening** `getDefaultBuiltInAgentSettings()` intentionally omits enabledTools; only the route/editor path layers DEFAULT_AGENT_TOOLS on top. Both main-generation resolution branches only re-inject tools for spotify, so tool-using built-ins materialized or fallback-resolved without going through the editor run tool-less. The runtime gate then skips building any tool context when enabledTools is empty. **Suggested fix** Fix the main-generation resolver so it matches the retry path for ALL built-ins, covering both the persisted (enabledConfigs) and first-generation (builtInFallbacks) paths, using `!Array.isArray` semantics so an explicit empty enabledTools (user removed all tools) is preserved, and excluding spotify (its provider-aware block is untouched). After the spotify block at line 290 (enabledConfigs loop): ```ts if ( cfg.type !== "spotify" && BUILT_IN_AGENTS.some((agent) => agent.id === cfg.type) && !Array.isArray(settings.enabledTools) && (DEFAULT_AGENT_TOOLS[cfg.type as string]?.length ?? 0) > 0 ) { settings.enabledTools = [...DEFAULT_AGENT_TOOLS[cfg.type as string]!]; } ``` After the spotify block at line 409 (builtInFallbacks loop): ```ts if ( builtIn.id !== "spotify" && !Array.isArray(builtInSettings.enabledTools) && (DEFAULT_AGENT_TOOLS[builtIn.id]?.length ?? 0) > 0 ) { builtInSettings.enabledTools = [...DEFAULT_AGENT_TOOLS[builtIn.id]!]; } ``` (BUILT_IN_AGENTS and DEFAULT_AGENT_TOOLS are already imported in agent-resolution.ts.) This also re-injects defaults for already-persisted tool-less rows. Regression avoided: patching only `ensureBuiltinConfig` (the suggested alt) is INSUFFICIENT — it does not fix the first-generation builtInFallbacks path (which runs before any DB row exists) nor existing tool-less rows. And the `!Array.isArray` check (not the spotify block's `length === 0` predicate) is required so a user who deliberately removed all tools in the editor doesn't get them silently re-enabled. Optionally also seed enabledTools in `ensureBuiltinConfig` for consistency, but it is not sufficient alone. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in merged staging PR #3004.

<!-- gh-comment-id:4832281572 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in merged staging PR #3004.
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#1568
No description provided.