Skip to content

Tool Agent in the Loop using only first item #14032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
anflsc2024 opened this issue Mar 18, 2025 · 9 comments · May be fixed by #15250
Open

Tool Agent in the Loop using only first item #14032

anflsc2024 opened this issue Mar 18, 2025 · 9 comments · May be fixed by #15250
Labels
in linear Issue or PR has been created in Linear for internal review In Review We are reviewing the issue

Comments

@anflsc2024
Copy link

Describe the problem/error/question

The agent retains or uses only the first index at the loop's prompt. The results the agent returns are always the same.

What is the error message (if any)?

There is no error message.

Please share your workflow/screenshots/recording

Image

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
⚠️ WARNING ⚠️ If you have sensitive data in your workflow (like API keys), please remove it before sharing.

Share the output returned by the last node

Debug info

core

  • n8nVersion: 1.82.3
  • platform: npm
  • nodeJsVersion: 20.18.3
  • database: sqlite
  • executionMode: regular
  • concurrency: -1
  • license: community

storage

  • success: all
  • error: all
  • progress: false
  • manual: true
  • binaryMode: memory

pruning

  • enabled: true
  • maxAge: 336 hours
  • maxCount: 10000 executions

client

  • userAgent: mozilla/5.0 (x11; linux x86_64) applewebkit/537.36 (khtml, like gecko) chrome/134.0.0.0 safari/537.36
  • isTouchDevice: false

Generated at: 2025-03-18T05:42:48.845Z}

@Joffcom
Copy link
Member

Joffcom commented Mar 18, 2025

Hey @anflsc2024,

We have created an internal ticket to look into this which we will be tracking as "GHC-1267"

@Joffcom Joffcom added the in linear Issue or PR has been created in Linear for internal review label Mar 18, 2025
@anflsc2024
Copy link
Author

"output":
"Agent stopped due to max iterations."

I found the reason. I think the max iterations of 6 exactly of one act I loop through

@anflsc2024 anflsc2024 changed the title Agent in the Loop Agent in the Loop max iterations with tool use Mar 18, 2025
@Joffcom
Copy link
Member

Joffcom commented Mar 19, 2025

Hey @anflsc2024

That would do it, so as you are hitting the max iterations I don't think there is a bug here. Let me know if you believe this to be a bug still and we can work out what to do next.

@Joffcom Joffcom added the Needs Feedback Waiting for further input or clarification. label Mar 19, 2025
@anflsc2024
Copy link
Author

I still think there is a bug. Only the first item from the loop is processed in a continuous loop. I only got it working now by placing the agent in a sub-workflow. This indicates to me that there's something wrong with the main implementation.

@Joffcom Joffcom removed the Needs Feedback Waiting for further input or clarification. label Mar 20, 2025
@Joffcom
Copy link
Member

Joffcom commented Mar 21, 2025

Hey @anflsc2024,

Can you clarify what the bug is and provide a minimal workflow that reproduces it? to me it looks like it is working as expected if the Agent node is hitting a limit and not outputting an item the loop will finish this also happens with normal nodes so we have the option to continue on error and always output data so the output can be checked and passed back to the loop for the next run.

@Joffcom Joffcom added the Needs Feedback Waiting for further input or clarification. label Mar 21, 2025
@anflsc2024
Copy link
Author

Bug.json

Here you can import the workflow

@Joffcom Joffcom removed the Needs Feedback Waiting for further input or clarification. label Mar 21, 2025
@anflsc2024 anflsc2024 changed the title Agent in the Loop max iterations with tool use Tool Agent in the Loop using only first item Mar 23, 2025
@gavinkwang
Copy link

I encountered the same problem, occasionally. During the loop, a node gets the data of the previous loop.

@Joffcom
Copy link
Member

Joffcom commented May 6, 2025

Hey @anflsc2024,

Looking at your example workflow in the ScenePrompt code node you are using $input.first() which will always use the first input item, This is resulting in the same prompt being returning 15 times which is why it is using the same data.

By changing your code node to use the below it is running loops as expected.

// Process each input item individually and return a prompt for each
// Using itemsArray to ensure we preserve the original order
const result = [];

// Loop through each input item in the original order
for (const item of $input.all()) {
  // Create a prompt for this item
  result.push({
    Prompt: `You are an experienced anime storyboard artist and director for a detective anime series. Analyze the following scene and determine the optimal number and type of key frames needed to visually tell this story.
    
    SCENE: ${item.json.Scene || ''}
    Prompt: ${item.json.prompt || ''}
    Act: ${item.json.Act || ''}
    
    Your Task is to determine how many key frames are optimal for this scene. For EACH frame, create a detailed image generation prompt an use the **WriteImagePrompt Tool** with the following format:
    - Scene: [Act, scene number, frame number: short frame title]
    - ImagePrompt: [the image prompt]
    Create the prompts to give an image generator precise instructions on exactly how the image should look. Each shot should capture an important moment in the scene, and together they should cover the entire narrative development of the scene.`
  });
}

// Return all the processed items
return result;

@gavinkwang if you have a way to reproduce this issue it would be great to see it in in a workflow form.

@Joffcom Joffcom added the Needs Feedback Waiting for further input or clarification. label May 6, 2025
@Joffcom
Copy link
Member

Joffcom commented May 6, 2025

@anflsc2024 after some more digging the team has managed to find an issue while looking at this, When using Tools it looks like the items are not correctly looped.

@Joffcom Joffcom added In Review We are reviewing the issue and removed In Review We are reviewing the issue Needs Feedback Waiting for further input or clarification. labels May 6, 2025
@ggozad ggozad linked a pull request May 9, 2025 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in linear Issue or PR has been created in Linear for internal review In Review We are reviewing the issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants