Skip to content

Fix recursion limit error on followup question#301

Merged
charlesLoder merged 1 commit intodeploy/prototypefrom
5457-graceful-recursion-recover
Mar 20, 2025
Merged

Fix recursion limit error on followup question#301
charlesLoder merged 1 commit intodeploy/prototypefrom
5457-graceful-recursion-recover

Conversation

@charlesLoder
Copy link
Copy Markdown

Description

If a GraphRecursionError was hit, the next user question would fail. This PR prevents that while also lowering the recursion limit

Summary of changes

  • sets MAX_RECURSION_LIMIT back to 8
  • updates langchain-aws to version 0.2.16 where a patch fixes the issue
  • updates the requirements.txt files as redeploying the stack was causing some requirements to not be included somehow

Test

It's helpful to set MAX_RECURSION_LIMIT to 4 or 6 to hit the recursion limit sooner

It's also helpful to recreate the .venv and reinstall the deps from the new requirements.txt

Deploy the stack.

Send in a question that triggers a lot of tool calls:

{
    "ref": "abc123",
    "stream_response": false,
    "message": "chat",
    "forget": true,
    "auth": "{{FOREVER_SUPERUSER_TOKEN}}",
    "question": "Tell me how many objects are there about Obama and explain how the items relate to the Berkeley Folk Festival where Phil Ochs and Joan Baez played, and maybe Miles Davis did too? Did Big Mama Thornton play at is as well?"
}

In the logs, should see the appropriate error:

Recursion error: Recursion limit of 4 reached without hitting a stop condition. You can increase the limit by setting the `recursion_limit` config key.

Send in a new question:

{
    "ref": "abc123",
    "stream_response": false,
    "message": "chat",
    "forget": false,
    "auth": "{{FOREVER_SUPERUSER_TOKEN}}",
    "question": "What about Miles Davis?"
}

The previous error of:

ERROR] EventStreamError: An error occurred (validationException) when calling the InvokeModelWithResponseStream operation: messages.12: Did not find 1 `tool_result` block(s) at the beginning of this message. Messages following `tool_use` blocks must begin with a matching number of `tool_result` blocks.

will not happen.

If the recursion limit is low, like 4, you may hit another recursion limit error, but that's expected.

Notes

The requirements.txt files were updated the standard way — pip freeze > requirements.txt — including all deps in the project.

@charlesLoder charlesLoder force-pushed the 5457-graceful-recursion-recover branch from 40056f6 to 1f277d9 Compare March 20, 2025 13:49
@charlesLoder
Copy link
Copy Markdown
Author

Updated to just upgrade langchain-aws to 0.2.x

@charlesLoder charlesLoder merged commit 7713d66 into deploy/prototype Mar 20, 2025
1 check passed
@charlesLoder charlesLoder deleted the 5457-graceful-recursion-recover branch March 20, 2025 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants