You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importosfromdotenvimportload_dotenvfromstrandsimportAgentfromstrands.models.openaiimportOpenAIModelfromstrands_toolsimportcalculatorload_dotenv()
importlogging# Enables Strands debug log levellogging.getLogger("strands").setLevel(logging.DEBUG)
# Sets the logging format and streams logs to stderrlogging.basicConfig(
format="%(levelname)s | %(name)s | %(message)s",
handlers=[logging.StreamHandler()]
)
model=OpenAIModel(
client_args={
"api_key": os.getenv("SILICONFLOW_API_KEY"),
"base_url": "https://api.siliconflow.cn/v1",
},
# **model_configmodel_id="Qwen/Qwen3-8B",
params={
"max_tokens": 1000,
"temperature": 0.7,
}
)
agent=Agent(model=model, tools=[calculator])
response=agent("What is 2+2")
print(response)
And the model answer normally at first. But when it calls the tool:
...[more response from the qwen3-8B model]
safe, specifying mode as evaluate makes it clear. Variables, wrt, point, order aren't applicable here. So the tool call should be {"name": "calculator", "arguments": {"expression": "2+2", "mode": "evaluate"}}. That should compute the result correctly.
Tool #1: calculator
DEBUG | strands.models.openai | finished streaming response from model
DEBUG | strands.event_loop.event_loop | tool_use=<{'toolUseId': '019818996ce0cd7a3d38ea922dd06efe', 'name': 'calculator', 'input': {'expression': '2+2', 'mode': 'evaluate'}}> | streaming
DEBUG | strands.tools.registry | getting tool configurations
DEBUG | strands.tools.registry | tool_name= | loaded tool config
DEBUG | strands.tools.registry | tool_count=<1> | tools configured
DEBUG | strands.tools.registry | getting tool configurations
DEBUG | strands.tools.registry | tool_name= | loaded tool config
DEBUG | strands.tools.registry | tool_count=<1> | tools configured
DEBUG | strands.event_loop.streaming | model=<<strands.models.openai.OpenAIModel object at 0x000001968348F0E0>> | streaming messages
DEBUG | strands.event_loop.streaming | removed blank message context text
DEBUG | strands.models.openai | formatting request
DEBUG | strands.models.openai | formatted request=<{'messages': [{'role': 'user', 'content': [{'text': 'What is 2+2', 'type': 'text'}]}, {'role': 'assistant', 'content': [], 'tool_calls': [{'function': {'arguments': '{"expression": "2+2", "mode": "evaluate"}', 'name': 'calculator'}, 'id': '019818996ce0cd7a3d38ea922dd06efe', 'type': 'function'}]}, {'role': 'tool', 'tool_call_id': '019818996ce0cd7a3d38ea922dd06efe', 'content': [{'text': 'Result: 4', 'type': 'text'}]}], 'model': 'Qwen/Qwen3-8B', 'stream': True, 'stream_options': {'include_usage': True}, 'tools': [{'type': 'function', 'function': {'name': 'calculator', 'description': 'Calculator powered by SymPy for comprehensive mathematical operations.\n\nThis tool provides advanced mathematical functionality through multiple operation modes,\nincluding expression evaluation, equation solving, calculus operations (derivatives, integrals),\nlimits, series expansions, and matrix operations. Results are formatted with appropriate\nprecision and can be displayed in scientific notation when needed.\n\nHow It Works:\n------------\n1. The function parses the mathematical expression using SymPy's parser\n2. Based on the selected mode, it routes the expression to the appropriate handler\n3. Variables and constants are substituted with their values when provided\n4. The expression is evaluated symbolically and/or numerically as appropriate\n5. Results are formatted based on precision preferences and value magnitude\n6. Rich output is generated with operation details and formatted results\n\nOperation Modes:\n--------------\n- evaluate: Calculate the value of a mathematical expression\n- solve: Find solutions to an equation or system of equations\n- derive: Calculate derivatives of an expression\n- integrate: Find the indefinite integral of an expression\n- limit: Evaluate the limit of an expression at a point\n- series: Generate series expansion of an expression\n- matrix: Perform matrix operations\n\nCommon Usage Scenarios:\n---------------------\n- Basic calculations: Evaluating arithmetic expressions\n- Equation solving: Finding roots of polynomials or systems of equations\n- Calculus: Computing derivatives and integrals for analysis\n- Engineering analysis: Working with scientific notations and constants\n- Mathematics education: Visualizing step-by-step solutions\n- Data science: Matrix operations and statistical calculations\n\nArgs:\n expression: The mathematical expression to evaluate, such as "2 + 2 * 3",\n "x2 + 2*x + 1", or "sin(pi/2)". For matrix operations, use array\n notation like "[[1, 2], [3, 4]]".\n mode: The calculation mode to use. Options are:\n - "evaluate": Compute the value of the expression (default)\n - "solve": Solve an equation or system of equations\n - "derive": Calculate the derivative of an expression\n - "integrate": Find the indefinite integral of an expression\n - "limit": Calculate the limit of an expression at a point\n - "series": Generate a series expansion of an expression\n - "matrix": Perform matrix operations\n precision: Number of decimal places for the result (default: 10).\n Higher values provide more precise output but may impact performance.\n scientific: Whether to use scientific notation for numbers (default: False).\n When True, formats large and small numbers using scientific notation.\n force_numeric: Force numeric evaluation of symbolic expressions (default: False).\n When True, tries to convert symbolic results to numeric values.\n variables: Optional dictionary of variable names and their values to substitute\n in the expression, e.g., {"a": 1, "b": 2}.\n wrt: Variable to differentiate or integrate with respect to (required for\n "derive" and "integrate" modes).\n point: Point at which to evaluate a limit (required for "limit" mode).\n Use "oo" for infinity.\n order: Order of derivative or series expansion (optional for "derive" and\n "series" modes, default is 1 for derivatives and 5 for series).\n\nReturns:\n Dict containing status and response content in the format:\n {\n "status": "success|error",\n "content": [{"text": "Result: <calculated_result>"}]\n }\n\n Success case: Returns the calculation result with appropriate formatting\n Error case: Returns information about what went wrong during calculation\n\nNotes:\n - For equation solving, set the expression equal to zero implicitly (x2 + 1 means x2 + 1 = 0)\n - Use 'pi' and 'e' for mathematical constants\n - The 'wrt' parameter is required for differentiation and integration\n - Matrix expressions use Python-like syntax: [[1, 2], [3, 4]]\n - Precision control impacts display only, internal calculations use higher precision\n - Symbolic results are returned when possible unless force_numeric=True', 'parameters': {'properties': {'expression': {'description': 'The mathematical expression to evaluate, such as "2 + 2 * 3",\n"x2 + 2*x + 1", or "sin(pi/2)". For matrix operations, use array\nnotation like "[[1, 2], [3, 4]]".', 'type': 'string'}, 'mode': {'default': None, 'description': 'The calculation mode to use. Options are:\n- "evaluate": Compute the value of the expression (default)\n- "solve": Solve an equation or system of equations\n- "derive": Calculate the derivative of an expression\n- "integrate": Find the indefinite integral of an expression\n- "limit": Calculate the limit of an expression at a point\n- "series": Generate a series expansion of an expression\n- "matrix": Perform matrix operations', 'type': 'string'}, 'precision': {'default': None, 'description': 'Number of decimal places for the result (default: 10).\nHigher values provide more precise output but may impact performance.', 'type': 'integer'}, 'scientific': {'default': None, 'description': 'Whether to use scientific notation for numbers (default: False).\nWhen True, formats large and small numbers using scientific notation.', 'type': 'boolean'}, 'force_numeric': {'default': None, 'description': 'Force numeric evaluation of symbolic expressions (default: False).\nWhen True, tries to convert symbolic results to numeric values.', 'type': 'boolean'}, 'variables': {'default': None, 'description': 'Optional dictionary of variable names and their values to substitute\nin the expression, e.g., {"a": 1, "b": 2}.', 'type': 'object'}, 'wrt': {'default': None, 'description': 'Variable to differentiate or integrate with respect to (required for\n"derive" and "integrate" modes).', 'type': 'string'}, 'point': {'default': None, 'description': 'Point at which to evaluate a limit (required for "limit" mode).\nUse "oo" for infinity.', 'type': 'string'}, 'order': {'default': None, 'description': 'Order of derivative or series expansion (optional for "derive" and\n"series" modes, default is 1 for derivatives and 5 for series).', 'type': 'integer'}}, 'required': ['expression'], 'type': 'object'}}}], 'max_tokens': 1000, 'temperature': 0.7}>
DEBUG | strands.models.openai | invoking model
ERROR | strands.event_loop.event_loop | cycle failed
Traceback (most recent call last):
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 210, in event_loop_cycle
async for event in events:
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 471, in _handle_tool_execution
async for event in events:
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 272, in recurse_event_loop
async for event in events:
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 182, in event_loop_cycle
raise e
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 130, in event_loop_cycle
async for event in stream_messages(agent.model, agent.system_prompt, agent.messages, tool_specs):
...<3 lines>...
}
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\streaming.py", line 318, in stream_messages
async for event in process_stream(chunks):
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\streaming.py", line 273, in process_stream
async for chunk in chunks:
...<16 lines>...
handle_redact_content(chunk["redactContent"], state)
File "F:\agentProject.venv\Lib\site-packages\strands\models\openai.py", line 347, in stream
response = await self.client.chat.completions.create(**request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\agentProject.venv\Lib\site-packages\openai\resources\chat\completions\completions.py", line 2028, in create
return await self._post(
^^^^^^^^^^^^^^^^^
...<45 lines>...
)
^
File "F:\agentProject.venv\Lib\site-packages\openai_base_client.py", line 1784, in post
return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\agentProject.venv\Lib\site-packages\openai_base_client.py", line 1584, in request
raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'code': 20015, 'message': 'Input should be a valid string', 'data': None}
DEBUG | strands.agent.conversation_manager.sliding_window_conversation_manager | message_count=<3>, window_size=<40> | skipping context reduction
Traceback (most recent call last):
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 210, in event_loop_cycle
async for event in events:
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 471, in _handle_tool_execution
async for event in events:
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 272, in recurse_event_loop
async for event in events:
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 182, in event_loop_cycle
raise e
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 130, in event_loop_cycle
async for event in stream_messages(agent.model, agent.system_prompt, agent.messages, tool_specs):
...<3 lines>...
}
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\streaming.py", line 318, in stream_messages
async for event in process_stream(chunks):
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\streaming.py", line 273, in process_stream
async for chunk in chunks:
...<16 lines>...
handle_redact_content(chunk["redactContent"], state)
File "F:\agentProject.venv\Lib\site-packages\strands\models\openai.py", line 347, in stream
response = await self.client.chat.completions.create(**request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\agentProject.venv\Lib\site-packages\openai\resources\chat\completions\completions.py", line 2028, in create
return await self._post(
^^^^^^^^^^^^^^^^^
...<45 lines>...
)
^
File "F:\agentProject.venv\Lib\site-packages\openai_base_client.py", line 1784, in post
return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\agentProject.venv\Lib\site-packages\openai_base_client.py", line 1584, in request
raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'code': 20015, 'message': 'Input should be a valid string', 'data': None}
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "F:\agentProject\quick_test.py", line 38, in
response = agent("What is 2+2")
File "F:\agentProject.venv\Lib\site-packages\strands\agent\agent.py", line 379, in call
return future.result()
~~~~~~~~~~~~~^^
File "C:\Users<MY_USER_NAME>\AppData\Local\Programs\Python\Python313\Lib\concurrent\futures_base.py", line 456, in result
return self.__get_result()
~~~~~~~~~~~~~~~~~^^
File "C:\Users<MY_USER_NAME>\AppData\Local\Programs\Python\Python313\Lib\concurrent\futures_base.py", line 401, in __get_result
raise self.exception
File "C:\Users<MY_USER_NAME>\AppData\Local\Programs\Python\Python313\Lib\concurrent\futures\thread.py", line 59, in run
result = self.fn(*self.args, **self.kwargs)
File "F:\agentProject.venv\Lib\site-packages\opentelemetry\instrumentation\threading_init.py", line 171, in wrapped_func
return original_func(*func_args, **func_kwargs)
File "F:\agentProject.venv\Lib\site-packages\strands\agent\agent.py", line 375, in execute
return asyncio.run(self.invoke_async(prompt, **kwargs))
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\MY_USER_NAME>\AppData\Local\Programs\Python\Python313\Lib\asyncio\runners.py", line 195, in run
return runner.run(main)
~~~~~~~~~~^^^^^^
File "C:\Users<MY_USER_NAME>\AppData\Local\Programs\Python\Python313\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "C:\Users<MY_USER_NAME>\AppData\Local\Programs\Python\Python313\Lib\asyncio\base_events.py", line 725, in run_until_complete
return future.result()
~~~~~~~~~~~~~^^
File "F:\agentProject.venv\Lib\site-packages\strands\agent\agent.py", line 400, in invoke_async
async for event in events:
_ = event
File "F:\agentProject.venv\Lib\site-packages\strands\agent\agent.py", line 510, in stream_async
async for event in events:
...<2 lines>...
yield event["callback"]
File "F:\agentProject.venv\Lib\site-packages\strands\agent\agent.py", line 546, in _run_loop
async for event in events:
...<13 lines>...
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\agent\agent.py", line 585, in _execute_event_loop_cycle
async for event in events:
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 240, in event_loop_cycle
raise EventLoopException(e, invocation_state["request_state"]) from e
strands.types.exceptions.EventLoopException: Error code: 400 - {'code': 20015, 'message': 'Input should be a valid string', 'data': None}
And I can't understand why this error occurs. Could you please help me with this? I would greatly appreciate any assistance. Thank you!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
And the model answer normally at first. But when it calls the tool:
...[more response from the qwen3-8B model]
safe, specifying mode as evaluate makes it clear. Variables, wrt, point, order aren't applicable here. So the tool call should be {"name": "calculator", "arguments": {"expression": "2+2", "mode": "evaluate"}}. That should compute the result correctly.
Tool #1: calculator
DEBUG | strands.models.openai | finished streaming response from model
DEBUG | strands.event_loop.event_loop | tool_use=<{'toolUseId': '019818996ce0cd7a3d38ea922dd06efe', 'name': 'calculator', 'input': {'expression': '2+2', 'mode': 'evaluate'}}> | streaming
DEBUG | strands.tools.registry | getting tool configurations
DEBUG | strands.tools.registry | tool_name= | loaded tool config
DEBUG | strands.tools.registry | tool_count=<1> | tools configured
DEBUG | strands.tools.registry | getting tool configurations
DEBUG | strands.tools.registry | tool_name= | loaded tool config
DEBUG | strands.tools.registry | tool_count=<1> | tools configured
DEBUG | strands.event_loop.streaming | model=<<strands.models.openai.OpenAIModel object at 0x000001968348F0E0>> | streaming messages
DEBUG | strands.event_loop.streaming | removed blank message context text
DEBUG | strands.models.openai | formatting request
DEBUG | strands.models.openai | formatted request=<{'messages': [{'role': 'user', 'content': [{'text': 'What is 2+2', 'type': 'text'}]}, {'role': 'assistant', 'content': [], 'tool_calls': [{'function': {'arguments': '{"expression": "2+2", "mode": "evaluate"}', 'name': 'calculator'}, 'id': '019818996ce0cd7a3d38ea922dd06efe', 'type': 'function'}]}, {'role': 'tool', 'tool_call_id': '019818996ce0cd7a3d38ea922dd06efe', 'content': [{'text': 'Result: 4', 'type': 'text'}]}], 'model': 'Qwen/Qwen3-8B', 'stream': True, 'stream_options': {'include_usage': True}, 'tools': [{'type': 'function', 'function': {'name': 'calculator', 'description': 'Calculator powered by SymPy for comprehensive mathematical operations.\n\nThis tool provides advanced mathematical functionality through multiple operation modes,\nincluding expression evaluation, equation solving, calculus operations (derivatives, integrals),\nlimits, series expansions, and matrix operations. Results are formatted with appropriate\nprecision and can be displayed in scientific notation when needed.\n\nHow It Works:\n------------\n1. The function parses the mathematical expression using SymPy's parser\n2. Based on the selected mode, it routes the expression to the appropriate handler\n3. Variables and constants are substituted with their values when provided\n4. The expression is evaluated symbolically and/or numerically as appropriate\n5. Results are formatted based on precision preferences and value magnitude\n6. Rich output is generated with operation details and formatted results\n\nOperation Modes:\n--------------\n- evaluate: Calculate the value of a mathematical expression\n- solve: Find solutions to an equation or system of equations\n- derive: Calculate derivatives of an expression\n- integrate: Find the indefinite integral of an expression\n- limit: Evaluate the limit of an expression at a point\n- series: Generate series expansion of an expression\n- matrix: Perform matrix operations\n\nCommon Usage Scenarios:\n---------------------\n- Basic calculations: Evaluating arithmetic expressions\n- Equation solving: Finding roots of polynomials or systems of equations\n- Calculus: Computing derivatives and integrals for analysis\n- Engineering analysis: Working with scientific notations and constants\n- Mathematics education: Visualizing step-by-step solutions\n- Data science: Matrix operations and statistical calculations\n\nArgs:\n expression: The mathematical expression to evaluate, such as "2 + 2 * 3",\n "x2 + 2*x + 1", or "sin(pi/2)". For matrix operations, use array\n notation like "[[1, 2], [3, 4]]".\n mode: The calculation mode to use. Options are:\n - "evaluate": Compute the value of the expression (default)\n - "solve": Solve an equation or system of equations\n - "derive": Calculate the derivative of an expression\n - "integrate": Find the indefinite integral of an expression\n - "limit": Calculate the limit of an expression at a point\n - "series": Generate a series expansion of an expression\n - "matrix": Perform matrix operations\n precision: Number of decimal places for the result (default: 10).\n Higher values provide more precise output but may impact performance.\n scientific: Whether to use scientific notation for numbers (default: False).\n When True, formats large and small numbers using scientific notation.\n force_numeric: Force numeric evaluation of symbolic expressions (default: False).\n When True, tries to convert symbolic results to numeric values.\n variables: Optional dictionary of variable names and their values to substitute\n in the expression, e.g., {"a": 1, "b": 2}.\n wrt: Variable to differentiate or integrate with respect to (required for\n "derive" and "integrate" modes).\n point: Point at which to evaluate a limit (required for "limit" mode).\n Use "oo" for infinity.\n order: Order of derivative or series expansion (optional for "derive" and\n "series" modes, default is 1 for derivatives and 5 for series).\n\nReturns:\n Dict containing status and response content in the format:\n {\n "status": "success|error",\n "content": [{"text": "Result: <calculated_result>"}]\n }\n\n Success case: Returns the calculation result with appropriate formatting\n Error case: Returns information about what went wrong during calculation\n\nNotes:\n - For equation solving, set the expression equal to zero implicitly (x2 + 1 means x2 + 1 = 0)\n - Use 'pi' and 'e' for mathematical constants\n - The 'wrt' parameter is required for differentiation and integration\n - Matrix expressions use Python-like syntax: [[1, 2], [3, 4]]\n - Precision control impacts display only, internal calculations use higher precision\n - Symbolic results are returned when possible unless force_numeric=True', 'parameters': {'properties': {'expression': {'description': 'The mathematical expression to evaluate, such as "2 + 2 * 3",\n"x2 + 2*x + 1", or "sin(pi/2)". For matrix operations, use array\nnotation like "[[1, 2], [3, 4]]".', 'type': 'string'}, 'mode': {'default': None, 'description': 'The calculation mode to use. Options are:\n- "evaluate": Compute the value of the expression (default)\n- "solve": Solve an equation or system of equations\n- "derive": Calculate the derivative of an expression\n- "integrate": Find the indefinite integral of an expression\n- "limit": Calculate the limit of an expression at a point\n- "series": Generate a series expansion of an expression\n- "matrix": Perform matrix operations', 'type': 'string'}, 'precision': {'default': None, 'description': 'Number of decimal places for the result (default: 10).\nHigher values provide more precise output but may impact performance.', 'type': 'integer'}, 'scientific': {'default': None, 'description': 'Whether to use scientific notation for numbers (default: False).\nWhen True, formats large and small numbers using scientific notation.', 'type': 'boolean'}, 'force_numeric': {'default': None, 'description': 'Force numeric evaluation of symbolic expressions (default: False).\nWhen True, tries to convert symbolic results to numeric values.', 'type': 'boolean'}, 'variables': {'default': None, 'description': 'Optional dictionary of variable names and their values to substitute\nin the expression, e.g., {"a": 1, "b": 2}.', 'type': 'object'}, 'wrt': {'default': None, 'description': 'Variable to differentiate or integrate with respect to (required for\n"derive" and "integrate" modes).', 'type': 'string'}, 'point': {'default': None, 'description': 'Point at which to evaluate a limit (required for "limit" mode).\nUse "oo" for infinity.', 'type': 'string'}, 'order': {'default': None, 'description': 'Order of derivative or series expansion (optional for "derive" and\n"series" modes, default is 1 for derivatives and 5 for series).', 'type': 'integer'}}, 'required': ['expression'], 'type': 'object'}}}], 'max_tokens': 1000, 'temperature': 0.7}>
DEBUG | strands.models.openai | invoking model
ERROR | strands.event_loop.event_loop | cycle failed
Traceback (most recent call last):
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 210, in event_loop_cycle
async for event in events:
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 471, in _handle_tool_execution
async for event in events:
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 272, in recurse_event_loop
async for event in events:
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 182, in event_loop_cycle
raise e
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 130, in event_loop_cycle
async for event in stream_messages(agent.model, agent.system_prompt, agent.messages, tool_specs):
...<3 lines>...
}
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\streaming.py", line 318, in stream_messages
async for event in process_stream(chunks):
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\streaming.py", line 273, in process_stream
async for chunk in chunks:
...<16 lines>...
handle_redact_content(chunk["redactContent"], state)
File "F:\agentProject.venv\Lib\site-packages\strands\models\openai.py", line 347, in stream
response = await self.client.chat.completions.create(**request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\agentProject.venv\Lib\site-packages\openai\resources\chat\completions\completions.py", line 2028, in create
return await self._post(
^^^^^^^^^^^^^^^^^
...<45 lines>...
)
^
File "F:\agentProject.venv\Lib\site-packages\openai_base_client.py", line 1784, in post
return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\agentProject.venv\Lib\site-packages\openai_base_client.py", line 1584, in request
raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'code': 20015, 'message': 'Input should be a valid string', 'data': None}
DEBUG | strands.agent.conversation_manager.sliding_window_conversation_manager | message_count=<3>, window_size=<40> | skipping context reduction
Traceback (most recent call last):
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 210, in event_loop_cycle
async for event in events:
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 471, in _handle_tool_execution
async for event in events:
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 272, in recurse_event_loop
async for event in events:
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 182, in event_loop_cycle
raise e
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 130, in event_loop_cycle
async for event in stream_messages(agent.model, agent.system_prompt, agent.messages, tool_specs):
...<3 lines>...
}
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\streaming.py", line 318, in stream_messages
async for event in process_stream(chunks):
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\streaming.py", line 273, in process_stream
async for chunk in chunks:
...<16 lines>...
handle_redact_content(chunk["redactContent"], state)
File "F:\agentProject.venv\Lib\site-packages\strands\models\openai.py", line 347, in stream
response = await self.client.chat.completions.create(**request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\agentProject.venv\Lib\site-packages\openai\resources\chat\completions\completions.py", line 2028, in create
return await self._post(
^^^^^^^^^^^^^^^^^
...<45 lines>...
)
^
File "F:\agentProject.venv\Lib\site-packages\openai_base_client.py", line 1784, in post
return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\agentProject.venv\Lib\site-packages\openai_base_client.py", line 1584, in request
raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'code': 20015, 'message': 'Input should be a valid string', 'data': None}
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "F:\agentProject\quick_test.py", line 38, in
response = agent("What is 2+2")
File "F:\agentProject.venv\Lib\site-packages\strands\agent\agent.py", line 379, in call
return future.result()
~~~~~~~~~~~~~^^
File "C:\Users<MY_USER_NAME>\AppData\Local\Programs\Python\Python313\Lib\concurrent\futures_base.py", line 456, in result
return self.__get_result()
~~~~~~~~~~~~~~~~~^^
File "C:\Users<MY_USER_NAME>\AppData\Local\Programs\Python\Python313\Lib\concurrent\futures_base.py", line 401, in __get_result
raise self.exception
File "C:\Users<MY_USER_NAME>\AppData\Local\Programs\Python\Python313\Lib\concurrent\futures\thread.py", line 59, in run
result = self.fn(*self.args, **self.kwargs)
File "F:\agentProject.venv\Lib\site-packages\opentelemetry\instrumentation\threading_init.py", line 171, in wrapped_func
return original_func(*func_args, **func_kwargs)
File "F:\agentProject.venv\Lib\site-packages\strands\agent\agent.py", line 375, in execute
return asyncio.run(self.invoke_async(prompt, **kwargs))
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\MY_USER_NAME>\AppData\Local\Programs\Python\Python313\Lib\asyncio\runners.py", line 195, in run
return runner.run(main)
~~~~~~~~~~^^^^^^
File "C:\Users<MY_USER_NAME>\AppData\Local\Programs\Python\Python313\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "C:\Users<MY_USER_NAME>\AppData\Local\Programs\Python\Python313\Lib\asyncio\base_events.py", line 725, in run_until_complete
return future.result()
~~~~~~~~~~~~~^^
File "F:\agentProject.venv\Lib\site-packages\strands\agent\agent.py", line 400, in invoke_async
async for event in events:
_ = event
File "F:\agentProject.venv\Lib\site-packages\strands\agent\agent.py", line 510, in stream_async
async for event in events:
...<2 lines>...
yield event["callback"]
File "F:\agentProject.venv\Lib\site-packages\strands\agent\agent.py", line 546, in _run_loop
async for event in events:
...<13 lines>...
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\agent\agent.py", line 585, in _execute_event_loop_cycle
async for event in events:
yield event
File "F:\agentProject.venv\Lib\site-packages\strands\event_loop\event_loop.py", line 240, in event_loop_cycle
raise EventLoopException(e, invocation_state["request_state"]) from e
strands.types.exceptions.EventLoopException: Error code: 400 - {'code': 20015, 'message': 'Input should be a valid string', 'data': None}
And I can't understand why this error occurs. Could you please help me with this? I would greatly appreciate any assistance. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions