Skip to content
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

fix(AI Agent Node): Fix output parsing and empty tool input handling in AI Agent node #10970

Conversation

OlegIvaniv
Copy link
Contributor

@OlegIvaniv OlegIvaniv commented Sep 25, 2024

Summary

This PR addresses two issues in the AI Agent node:

  1. Output parser compatibility with memory
  2. Empty tool input handling for the Anthropic chat model

Output parser and memory compatibility

When using both an output parser and memory in the AI Agent node, we encountered an issue where the memory component requires the output to be a string. To resolve this, we now:

  • Stringify the parsed output before saving it to memory
  • Provide the parsed version to the user in the workflow

This ensures that the memory component receives the expected string format while maintaining the structured output for workflow operations.

Empty tool input handling for Anthropic

The Anthropic chat model expects tool inputs always to be objects. However, when using a tool that doesn't require arguments, the input would default to an empty string (''), causing errors. We've implemented a fix to:

  • Replace empty string inputs with empty objects
  • Prevent errors when using tools without arguments

Related Linear tickets, Github issues, and Community forum posts

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@n8n-assistant n8n-assistant bot added the n8n team Authored by the n8n team label Sep 27, 2024
Copy link
Contributor

@burivuhster burivuhster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I only have one minor suggestion about TS types

Copy link
Contributor

@burivuhster burivuhster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link

cypress bot commented Sep 30, 2024

n8n    Run #7087

Run Properties:  status check passed Passed #7087  •  git commit b9d3e33a92: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 OlegIvaniv 🗃️ e2e/*
Project n8n
Branch Review ai-317-using-output-parsers-with-memory-throws-error-on-subsequent
Run status status check passed Passed #7087
Run duration 04m 19s
Commit git commit b9d3e33a92: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 OlegIvaniv 🗃️ e2e/*
Committer Oleg Ivaniv
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 432
View all changes introduced in this branch ↗︎

Copy link
Contributor

✅ All Cypress E2E specs passed

@OlegIvaniv OlegIvaniv merged commit 3a65bdc into master Sep 30, 2024
42 checks passed
@OlegIvaniv OlegIvaniv deleted the ai-317-using-output-parsers-with-memory-throws-error-on-subsequent branch September 30, 2024 08:09
MiloradFilipovic added a commit that referenced this pull request Sep 30, 2024
* master:
  feat(editor): Overhaul document title management (#10999)
  refactor(core): Organize all event maps (#10997)
  fix(AI Agent Node): Fix output parsing and empty tool input handling in AI Agent node (#10970)
This was referenced Oct 2, 2024
@janober
Copy link
Member

janober commented Oct 2, 2024

Got released with n8n@1.62.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
n8n team Authored by the n8n team Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants