Skip to content

[BUG] AttributeError: 'NoneType' object has no attribute 'prompt_tokens' with OpenAIModel #308

Open
@taget

Description

@taget

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.9

Python Version

3.12.9

Operating System

macOS 15.5

Installation Method

pip

Steps to Reproduce

    model = OpenAIModel(
        client_args={
            "api_key": "sk-xxxx",
            "base_url": "http://xxxxx:8080/v1/",
        },
        model_id="DeepSeek-V3-0324",
        params={
            "max_tokens": 100000,
            "temperature": 0.7,
            "stream": True  
        }
    )

when call tools like Tool #1: current_time
got error like this:

File "/Users/eliqiao/code/robot_src/cmds/test_results.py", line 134, in main
r = ag(args.message)
^^^^^^^^^^^^^^^^
File "/Users/eliqiao/code/robot_src/venv/lib/python3.12/site-packages/strands/agent/agent.py", line 391, in call
result = self._run_loop(prompt, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/eliqiao/code/robot_src/venv/lib/python3.12/site-packages/strands/agent/agent.py", line 521, in _run_loop
return self._execute_event_loop_cycle(invocation_callback_handler, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/eliqiao/code/robot_src/venv/lib/python3.12/site-packages/strands/agent/agent.py", line 549, in _execute_event_loop_cycle
stop_reason, message, metrics, state = event_loop_cycle(
^^^^^^^^^^^^^^^^^
File "/Users/eliqiao/code/robot_src/venv/lib/python3.12/site-packages/strands/event_loop/event_loop.py", line 171, in event_loop_cycle
raise e
File "/Users/eliqiao/code/robot_src/venv/lib/python3.12/site-packages/strands/event_loop/event_loop.py", line 138, in event_loop_cycle
for event in stream_messages(model, system_prompt, messages, tool_config):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/eliqiao/code/robot_src/venv/lib/python3.12/site-packages/strands/event_loop/streaming.py", line 326, in stream_messages
yield from process_stream(chunks, messages)
File "/Users/eliqiao/code/robot_src/venv/lib/python3.12/site-packages/strands/event_loop/streaming.py", line 281, in process_stream
for chunk in chunks:
^^^^^^
File "/Users/eliqiao/code/robot_src/venv/lib/python3.12/site-packages/strands/types/models/model.py", line 140, in converse
yield self.format_chunk(event)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/eliqiao/code/robot_src/venv/lib/python3.12/site-packages/strands/types/models/openai.py", line 283, in format_chunk
"inputTokens": event["data"].prompt_tokens,
^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'prompt_tokens'

Expected Behavior

no error

Actual Behavior

raise exception

Additional Context

chat with the agent "what the time is it now?" and agent will first call tool current_time then got above errors

Possible Solution

No response

Related Issues

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions