[GH-ISSUE #4615] [Issue]: Avoid repeated full-context LLM requests in Spotify Music DJ tool rounds #2521

Closed
opened 2026-10-21 05:49:27 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @SpicyMarinara on GitHub (Aug 4, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4615

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Spotify Music DJ tool use can make multiple sequential LLM requests for one agent run, resending the large agent prompt plus an increasingly long tool transcript on every round. One observed run made four real provider calls and consumed 78,934 total tokens, rather than performing one extraction/planning request followed by bounded server-side Spotify work.

Expected behavior

Music DJ selection should avoid repeatedly sending the full agent context to the model. Prefer one planning/extraction request with deterministic server-side Spotify tool execution where possible. One returned JSON list with songs.

If a follow-up model round is genuinely required, it should be tightly bounded, minimize repeated context and tool payloads, and make the resulting request count and token cost clear in debug output.

Actual behavior

executeAgentWithTools calls provider.chatComplete(loopMessages, ...) once per tool round. When the model returns tool calls, the Engine executes them, appends the assistant tool-call message and tool results to loopMessages, then sends the entire growing message list again.

The observed Music DJ run issued four sequential requests with prompt sizes of 17,531, 17,706, 21,290, and 21,689 tokens. The configured global tool-loop default permits up to 100 rounds.

Steps to reproduce

  1. Enable Spotify Music DJ with a language-model connection.
  2. Enable Marinara Agent Debug logging.
  3. Trigger a turn in which Music DJ searches for and starts appropriate music.
  4. Inspect the browser debug console.
  5. Observe multiple request round N / response round N pairs for the same Music DJ run, with the prompt token count repeated and growing each round.

Environment

  • Marinara Engine version: Not provided
  • Install type: Not provided
  • OS + version: Not provided
  • Browser or app shell: Browser debug console; exact browser/app shell not provided

Logs, screenshots, or video

request round 1: Music DJ (spotify) | gpt-5.6-sol
response round 1: Music DJ (spotify) | gpt-5.6-sol | prompt 17531, completion 70, reasoning 51, total 17601 tokens | 3888ms
request round 2: Music DJ (spotify) | gpt-5.6-sol
response round 2: Music DJ (spotify) | gpt-5.6-sol | prompt 17706, completion 115, reasoning 24, total 17821 tokens | 8611ms
request round 3: Music DJ (spotify) | gpt-5.6-sol
response round 3: Music DJ (spotify) | gpt-5.6-sol | prompt 21290, completion 255, reasoning 102, total 21545 tokens | 16625ms
request round 4: Music DJ (spotify) | gpt-5.6-sol
response round 4: Music DJ (spotify) | gpt-5.6-sol | prompt 21689, completion 278, reasoning 30, total 21967 tokens | 24527ms

Across the four calls:

  • Prompt tokens: 78,216
  • Completion tokens: 718
  • Total tokens: 78,934
  • End-to-end duration shown by the final cumulative debug timer: 24,527 ms

Additional context

This is Marinara Engine host-orchestration behavior: the Engine owns the tool loop, request construction, context replay, and compatibility handling even though Music DJ is a downloadable agent.

The current debug durationMs for each round is cumulative from the beginning of the agent run, not the duration of that individual request. Preserve a clear end-to-end measurement while making per-round request cost understandable.

Add regression coverage that records the provider call count and verifies the prompt/context passed to any necessary follow-up round.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @SpicyMarinara on GitHub (Aug 4, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4615 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Spotify Music DJ tool use can make multiple sequential LLM requests for one agent run, resending the large agent prompt plus an increasingly long tool transcript on every round. One observed run made four real provider calls and consumed 78,934 total tokens, rather than performing one extraction/planning request followed by bounded server-side Spotify work. ## Expected behavior Music DJ selection should avoid repeatedly sending the full agent context to the model. Prefer one planning/extraction request with deterministic server-side Spotify tool execution where possible. One returned JSON list with songs. If a follow-up model round is genuinely required, it should be tightly bounded, minimize repeated context and tool payloads, and make the resulting request count and token cost clear in debug output. ## Actual behavior `executeAgentWithTools` calls `provider.chatComplete(loopMessages, ...)` once per tool round. When the model returns tool calls, the Engine executes them, appends the assistant tool-call message and tool results to `loopMessages`, then sends the entire growing message list again. The observed Music DJ run issued four sequential requests with prompt sizes of 17,531, 17,706, 21,290, and 21,689 tokens. The configured global tool-loop default permits up to 100 rounds. ## Steps to reproduce 1. Enable Spotify Music DJ with a language-model connection. 2. Enable Marinara Agent Debug logging. 3. Trigger a turn in which Music DJ searches for and starts appropriate music. 4. Inspect the browser debug console. 5. Observe multiple `request round N` / `response round N` pairs for the same Music DJ run, with the prompt token count repeated and growing each round. ## Environment - Marinara Engine version: Not provided - Install type: Not provided - OS + version: Not provided - Browser or app shell: Browser debug console; exact browser/app shell not provided ## Logs, screenshots, or video ```text request round 1: Music DJ (spotify) | gpt-5.6-sol response round 1: Music DJ (spotify) | gpt-5.6-sol | prompt 17531, completion 70, reasoning 51, total 17601 tokens | 3888ms request round 2: Music DJ (spotify) | gpt-5.6-sol response round 2: Music DJ (spotify) | gpt-5.6-sol | prompt 17706, completion 115, reasoning 24, total 17821 tokens | 8611ms request round 3: Music DJ (spotify) | gpt-5.6-sol response round 3: Music DJ (spotify) | gpt-5.6-sol | prompt 21290, completion 255, reasoning 102, total 21545 tokens | 16625ms request round 4: Music DJ (spotify) | gpt-5.6-sol response round 4: Music DJ (spotify) | gpt-5.6-sol | prompt 21689, completion 278, reasoning 30, total 21967 tokens | 24527ms ``` Across the four calls: - Prompt tokens: 78,216 - Completion tokens: 718 - Total tokens: 78,934 - End-to-end duration shown by the final cumulative debug timer: 24,527 ms ## Additional context This is Marinara Engine host-orchestration behavior: the Engine owns the tool loop, request construction, context replay, and compatibility handling even though Music DJ is a downloadable agent. The current debug `durationMs` for each round is cumulative from the beginning of the agent run, not the duration of that individual request. Preserve a clear end-to-end measurement while making per-round request cost understandable. Add regression coverage that records the provider call count and verifies the prompt/context passed to any necessary follow-up round. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [x] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:49:27 +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#2521
No description provided.