Skip to content

s02运行报错 #195

@Opao-heng

Description

@Opao-heng

read_file:
#!/usr/bin/env python3

Harness: tool dispatch -- expanding what the model can reach.

"""
s02_tool_use.py - Tool dispatch + message normalization

The agent loop from s01 didn't change. We added tool
Traceback (most recent call last):
File "D:\Python\PyCharm\pycharm2025.2.1.1\PyCharm 2025.2.1.1\plugins\python-ce\helpers\pydev\pydevd.py", line 1648, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python\PyCharm\pycharm2025.2.1.1\PyCharm 2025.2.1.1\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python-Learn\03-learn-claude-code\learn-claude-code\agents\s02_tool_use.py", line 213, in
agent_loop(history)
~~~~~~~~~~^^^^^^^^^
File "D:\Python-Learn\03-learn-claude-code\learn-claude-code\agents\s02_tool_use.py", line 183, in agent_loop
response = client.messages.create(
model=MODEL, system=SYSTEM,
messages=normalize_messages(messages),
tools=TOOLS, max_tokens=8000,
)
File "C:\Users\User.conda\envs\liuheng_Agent\Lib\site-packages\anthropic_utils_utils.py", line 282, in wrapper
return func(*args, **kwargs)
File "C:\Users\User.conda\envs\liuheng_Agent\Lib\site-packages\anthropic\resources\messages\messages.py", line 996, in create
return self._post(
~~~~~~~~~~^
"/v1/messages",
^^^^^^^^^^^^^^^
...<30 lines>...
stream_cls=Stream[RawMessageStreamEvent],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "C:\Users\User.conda\envs\liuheng_Agent\Lib\site-packages\anthropic_base_client.py", line 1368, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\User.conda\envs\liuheng_Agent\Lib\site-packages\anthropic_base_client.py", line 1141, in request
raise self._make_status_error_from_response(err.response) from None
anthropic.BadRequestError: Error code: 400 - {'error': {'message': 'unexpected messages.2.content.0: tool_use_id found in tool_result blocks:
call_00_LMj5nEG9xTn9mGaEks2vVsPB. Each tool_result block must have a corresponding tool_use block in the previous message.', 'type':
'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}
python-BaseException 。一直运行不了

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions