Skip to content

[BUG] RecursionError + "input length and max_tokens exceed context limit: 142422 + 64000 > 204658" #152

Closed
@gargshilpi22

Description

@gargshilpi22

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

0.1.0

Python Version

3.10

Operating System

Amazon Linux 2

Installation Method

pip

Steps to Reproduce

RecursionError: maximum recursion depth exceeded

Error Description

When running the Strands agent, I'm encountering a context window overflow error followed by a recursion error.

Error Details

The primary error is a ContextWindowOverflowException with the following details:

input length and `max_tokens` exceed context limit: 142422 + 64000 > 204658

This indicates that the total tokens (input + max_tokens) exceeds the model's context window limit of 204,658 tokens.

Full Error Trace

Traceback (most recent call last):
  # ... [previous trace details]
  
strands.types.exceptions.ContextWindowOverflowException: An error occurred (validationException) when calling the ConverseStream operation: The model returned the following errors: input length and `max_tokens` exceed context limit: 142422 + 64000 > 204658, decrease input length or `max_tokens` and try again

This is followed by a recursion error while handling the initial exception:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "XXX/.venv/lib/python3.10/site-packages/strands/event_loop/event_loop.py", line 220, in event_loop_cycle
    return _handle_tool_execution(
  File "XXX/.venv/lib/python3.10/site-packages/strands/event_loop/event_loop.py", line 428, in _handle_tool_execution
    return recurse_event_loop(
  File "XXX/.venv/lib/python3.10/site-packages/strands/event_loop/event_loop.py", line 305, in recurse_event_loop
    ) = event_loop_cycle(**kwargs)
  File "XXX/.venv/lib/python3.10/site-packages/strands/event_loop/event_loop.py", line 163, in event_loop_cycle
    return handle_input_too_long_error(
  File "XXX/.venv/lib/python3.10/site-packages/strands/event_loop/error_handler.py", line 108, in handle_input_too_long_error

  File "XXX/.venv/lib/python3.10/site-packages/botocore/validate.py", line 213, in _validate
    getattr(self, f'_validate_{shape.type_name}')(
  File "XXX/.venv/lib/python3.10/site-packages/botocore/validate.py", line 54, in _on_passes_type_check
    return func(self, param, shape, errors, name)
  File "XXX/.venv/lib/python3.10/site-packages/botocore/validate.py", line 282, in _validate_structure
    self._validate(
  File "XXX/.venv/lib/python3.10/site-packages/botocore/validate.py", line 209, in _validate
    special_validator = self._check_special_validation_cases(shape)
  File "XXX/.venv/lib/python3.10/site-packages/botocore/validate.py", line 203, in _check_special_validation_cases
    if is_json_value_header(shape):
RecursionError: maximum recursion depth exceeded

Environment Details

  • Python version: 3.10
  • Package: Strands
  • Running in virtual environment

Question

Has anyone encountered this issue and found a solution? I'm particularly interested in best practices for handling large inputs with the Strands agent.


Please let me know if you need any additional information or clarification.

Expected Behavior

Recursion length should be handled.

Actual Behavior

Failed due to - RecursionError: maximum recursion depth exceeded

Additional Context

No response

Possible Solution

No response

Related Issues

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions