strands-agents/sdk-python

[BUG] Unssuported content type for "reasoning_content"

Opened this issue · 2 comments

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

1.13.1

Python Version

3.12.1

Operating System

macOS 15.6.1

Installation Method

pip

Steps to Reproduce

You can use this code snippet. Note that you can use for free this endpoint but with a ratelimit.

from strands import Agent
from strands.models.openai import OpenAIModel
from strands_tools import current_time

model = OpenAIModel(
    client_args={
        "api_key": "",
        "base_url": "https://oai.endpoints.kepler.ai.cloud.ovh.net/v1",
    },
    model_id="gpt-oss-120b"
)

agent = Agent(model=model, tools=[current_time])
agent("What is the current time?")

Expected Behavior

The response should give the current time.

Actual Behavior

It crashes without giving the actual time. The behavior is unexpected since it handles correctly the reasoning content by printing it in the console, but then crash.

Additional Context

(.venv) ➜  strands-agents-test python3 main.py 
We need to provide current time using tool.
Tool #1: current_time
cycle failed
Traceback (most recent call last):
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/event_loop/event_loop.py", line 154, in event_loop_cycle
    async for tool_event in tool_events:
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/event_loop/event_loop.py", line 445, in _handle_tool_execution
    async for event in events:
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/event_loop/event_loop.py", line 217, in recurse_event_loop
    async for event in events:
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/event_loop/event_loop.py", line 117, in event_loop_cycle
    async for model_event in model_events:
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/event_loop/event_loop.py", line 324, in _handle_model_execution
    raise e
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/event_loop/event_loop.py", line 272, in _handle_model_execution
    async for event in stream_messages(agent.model, agent.system_prompt, agent.messages, tool_specs):
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/event_loop/streaming.py", line 367, in stream_messages
    async for event in process_stream(chunks, start_time):
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/event_loop/streaming.py", line 316, in process_stream
    async for chunk in chunks:
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/models/openai.py", line 382, in stream
    request = self.format_request(messages, tool_specs, system_prompt, tool_choice)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/models/openai.py", line 264, in format_request
    "messages": self.format_request_messages(messages, system_prompt),
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/models/openai.py", line 218, in format_request_messages
    cls.format_request_message_content(content)
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/models/openai.py", line 131, in format_request_message_content
    raise TypeError(f"content_type=<{next(iter(content))}> | unsupported type")
TypeError: content_type=<reasoningContent> | unsupported type
Traceback (most recent call last):
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/event_loop/event_loop.py", line 154, in event_loop_cycle
    async for tool_event in tool_events:
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/event_loop/event_loop.py", line 445, in _handle_tool_execution
    async for event in events:
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/event_loop/event_loop.py", line 217, in recurse_event_loop
    async for event in events:
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/event_loop/event_loop.py", line 117, in event_loop_cycle
    async for model_event in model_events:
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/event_loop/event_loop.py", line 324, in _handle_model_execution
    raise e
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/event_loop/event_loop.py", line 272, in _handle_model_execution
    async for event in stream_messages(agent.model, agent.system_prompt, agent.messages, tool_specs):
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/event_loop/streaming.py", line 367, in stream_messages
    async for event in process_stream(chunks, start_time):
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/event_loop/streaming.py", line 316, in process_stream
    async for chunk in chunks:
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/models/openai.py", line 382, in stream
    request = self.format_request(messages, tool_specs, system_prompt, tool_choice)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/models/openai.py", line 264, in format_request
    "messages": self.format_request_messages(messages, system_prompt),
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/models/openai.py", line 218, in format_request_messages
    cls.format_request_message_content(content)
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/models/openai.py", line 131, in format_request_message_content
    raise TypeError(f"content_type=<{next(iter(content))}> | unsupported type")
TypeError: content_type=<reasoningContent> | unsupported type

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/aperture/Documents/Workspace/strands-agents-test/main.py", line 14, in <module>
    agent("What is the current time?")
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/agent/agent.py", line 419, in __call__
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/opentelemetry/instrumentation/threading/__init__.py", line 171, in wrapped_func
    return original_func(*func_args, **func_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/agent/agent.py", line 415, in execute
    return asyncio.run(self.invoke_async(prompt, invocation_state=invocation_state, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 684, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/agent/agent.py", line 450, in invoke_async
    async for event in events:
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/agent/agent.py", line 611, in stream_async
    async for event in events:
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/agent/agent.py", line 681, in _run_loop
    async for event in events:
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/agent/agent.py", line 720, in _execute_event_loop_cycle
    async for event in events:
  File "/Users/aperture/Documents/Workspace/strands-agents-test/.venv/lib/python3.12/site-packages/strands/event_loop/event_loop.py", line 185, in event_loop_cycle
    raise EventLoopException(e, invocation_state["request_state"]) from e
strands.types.exceptions.EventLoopException: content_type=<reasoningContent> | unsupported type

Possible Solution

No response

Related Issues

No response

Hi, thank you for this issue. After some investigation the following is my understanding and suggestion.

  • The current OpenAI model provider conforms to the Chat Completions API which does not document officially support for reasoning_content in its request body.
  • Furthermore, based on docs found in LiteLLM, it looks like reasoning_content can be part of a model's response, however, there is no official documentation for it being supported as part of a request when being sent to the model.
  • Additionally, the model card for gpt-oss-120b supports the Responses API and doesn't support the Chat Completions API.

My hypothesis is that the server at the endpoint "https://oai.endpoints.kepler.ai.cloud.ovh.net/v1" may be transforming the openai spec to support reasoning_content, however, this is not something officially documented by OpenAI.

Suggestion:

  • LiteLLM model provider currently supports reasoning_content and if possible may be better suited for your use-case.
  • Another approach to take may be to implement a custom model provider for your use-case that supports the format of the request and response expected.

To gracefully handle and drop the reasoningContent for openai model provider we make appropriate changes in this PR: #1099