mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #1389] [MERGED] Wire main-path tool calling into startGeneration #5057
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#5057
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1389
Author: @Romuromylus
Created: 5/27/2026
Status: ✅ Merged
Merged: 5/27/2026
Merged by: @Romuromylus
Base:
refactor← Head:fix/refactor-issue-1340-tool-call-parity📝 Commits (6)
1f1ae34Wire main-path tool calling into startGenerationd32f437Merge branch 'refactor' into fix/refactor-issue-1340-tool-call-parityf732e63Correct the synthetic main-agent comment on executeMainToolCalld11097eAddress CodeRabbit review on main-path tool callingda7a692Merge remote-tracking branch 'upstream/refactor' into fix/refactor-issue-1340-tool-call-parity9468de8Merge branch 'refactor' into fix/refactor-issue-1340-tool-call-parity📊 Changes
5 files changed (+1602 additions, -406 deletions)
View changed files
📝
src/engine/generation/agent-runner.ts(+22 -368)📝
src/engine/generation/generation-events.ts(+2 -0)➕
src/engine/generation/main-tool-loop.test.ts(+828 -0)📝
src/engine/generation/start-generation.ts(+203 -38)➕
src/engine/generation/tools-runtime.ts(+547 -0)📄 Description
Why this change
Closes #1340.
The refactor's
startGeneration(src/engine/generation/start-generation.ts) never passedtoolstodeps.llm.stream(...)and never handledtool_callchunks coming back, so the per-chatenableTools+activeToolIdssettings persisted byChatSettingsDrawerwere dead settings for the main character LLM call across every mode (chat / roleplay / game / conversation). All tool plumbing already existed scoped per-agent inagent-runner.ts, but was unreachable from the main character path. This was a regression versus the v1.6.x server build, where the main generation route resolved built-in + custom tools and ran a multi-turn tool-execution loop.The audit comment on #1340 asked to verify that transport, command handling, and prompt assembly all agree on conversation-mode tool behavior. They did not: the UI claimed tools available, storage persisted
enableTools/activeToolIds, and the transport / prompt-assembly layer ignored both. This change restores agreement across all three layers, mode-neutrally.What changed
src/engine/generation/tools-runtime.ts— extracts the shared tool helpers (built-in tool map, custom-tool loader,executeBuiltInTool, normalization, dice / lorebook helpers) fromagent-runner.tsand adds a mode-neutral public API (buildMainToolDefinitions,executeMainToolCall,chatToolsEnabledFor,chatActiveToolIdsFor). All extracted helpers are byte-identical to their previous behavior; the new API is additive.src/engine/generation/agent-runner.ts— deletes the moved functions and re-imports them from./tools-runtime. Agent-path behavior is unchanged.src/engine/generation/start-generation.ts— adds a singlestreamMainGenerationLoophelper called by both LLM branches (agents-enabled and directMessages). Each iteration streams from the model, collectstool_callchunks, executes them viaexecuteMainToolCall, appends the results back into the conversation, and re-streams. Iteration is capped atMAX_MAIN_TOOL_ITERATIONS = 8with a visiblephaseevent on cap-hit.src/engine/generation/generation-events.ts— two new variantstool_callandtool_resultso downstream consumers can observe the loop. No UI rendering is added in this PR — that is intentionally left for a follow-up.Design choices
chat.metadata.enableToolsis true andbuildMainToolDefinitionsreturns at least one usable tool. There is no read ofchat.modeanywhere in the new path. The change therefore restores parity uniformly across chat / roleplay / game / conversation; #1340 is framed as conversation-mode but the surface is broader.read_chat_summary,append_chat_summary,read_chat_variable, andwrite_chat_variableare inter-agent coordination primitives — they should not be exposed to the main character, matching the legacy server'sagentOnlyToolNamesset.enabledToolscontinue to receive it via the unchanged agent path.generate.routes.ts:5984-5990behavior.conversation: LlmMessage[]array between iterations but never flow intosaveAssistantMessage; only the final accumulated assistant content is persisted, matching legacy.Verification
pnpm checkpasses locally (check:architecture,check:frontend,check:rust,check:docs).pnpm testpasses (22 files / 128 tests including the newmain-tool-loop.test.tswith 13 deterministic tests covering all ten rows of the implementation's risk matrix: Spotify filter, infinite-loop cap, custom-tool execution failure surfacing, non-persistence of tool turns,enableTools: falsebyte-identical baseline, agent-only filter,activeToolIds: []semantics, mid-loop abort with no orphan tool-call events, Branch B parity with Branch A, and custom-vs-built-in name collision).cargo clippy --workspace --all-targets -- -D warningspasses.deps.llm.stream/deps.integrations.customTools.execute/deps.storage; no real network, no flaky asserts.Known caveat: streaming downgrade on some providers when tools are enabled
The
marinara-llmcrate's streaming router (src-tauri/crates/llm/src/lib.rs:95-119) only takes the true streaming path (stream_openai_compatible) whenrequest.tools.is_empty()for any provider that is notopenai_chatgpt, OpenAI Responses, Anthropic, Google, Google Vertex, or Claude subscription. Once tools are non-empty, those other providers fall through tocomplete_rich, which is a single non-streaming request that emits all tokens at once at the end of the turn.This is a pre-existing limitation of the LLM crate, not introduced by this PR — but this PR is the first commit that makes the user-facing
enableToolssetting actually reach the streaming router. As a result, enabling tools on chats backed by OpenRouter, raw OpenAI Chat Completions (non-Responses), Mistral, Groq, KoboldCpp, llama.cpp, Together, etc. will silently drop token-by-token streaming for those chats. Tool calls themselves still work; only the streaming UX changes.Tracking as a follow-up: extend
stream_openai_compatibleto support the OpenAI Chat Completions streaming-tool-delta path so the affected providers retain streaming UX with tools enabled.Follow-ups (deferred, not blocking this PR)
stream_openai_compatiblewith tool-call streaming for non-Responses-API providers (per the caveat above).tool_call/tool_resultevents in the chat surface. This PR keeps the events as runtime signal only.deps.llm.streamiteration boundary; a 30s+ webhook would still complete before the loop cancels. Matches existing agent-runner behavior.customToolDefinitionreturnsLLMToolDefinition(fromgeneration-core/llm/base-provider) whilebuildMainToolDefinitionspacks the result intoLlmToolDefinition[](fromcapabilities/llm). Structurally identical so typecheck passes, but worth consolidating in a future cleanup.updateChatMetadata(pre-existing inagent-runner.ts, now reachable from a second call site).includeSpotify: falseis ever lifted frombuildMainToolDefinitions, the caller must supply a real Spotify-agent id (orspotifyAgentIdmust be refactored to fall back to""sofind_by_field(... "type", "spotify")is reached) — the synthetic"main"literal will NOT resolve to default credentials. See the updated comment onexecuteMainToolCallfor context.Summary by CodeRabbit
New Features
tool_callandtool_resultevent types for improved tool execution visibility.Refactor
Tests
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.