Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No error handling around empty messages #36

Open
spocksbrain opened this issue May 11, 2024 · 3 comments
Open

No error handling around empty messages #36

spocksbrain opened this issue May 11, 2024 · 3 comments

Comments

@spocksbrain
Copy link

I have also run across this error a number of times.

Traceback (most recent call last):
File "C:\Users\Spocksbrain\Documents\Code_Projects\maestro\maestro.py", line 246, in
sub_task_result = haiku_sub_agent(sub_task_prompt, search_query, haiku_tasks, use_search)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Spocksbrain\Documents\Code_Projects\maestro\maestro.py", line 117, in haiku_sub_agent
haiku_response = client.messages.create(
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Spocksbrain\Documents\Code_Projects\maestro\maestor01\Lib\site-packages\anthropic_utils_utils.py", line 277, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Spocksbrain\Documents\Code_Projects\maestro\maestor01\Lib\site-packages\anthropic\resources\messages.py", line 681, in create
return self._post(
^^^^^^^^^^^
File "C:\Users\Spocksbrain\Documents\Code_Projects\maestro\maestor01\Lib\site-packages\anthropic_base_client.py", line 1239, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Spocksbrain\Documents\Code_Projects\maestro\maestor01\Lib\site-packages\anthropic_base_client.py", line 921, in request
return self._request(
^^^^^^^^^^^^^^
File "C:\Users\Spocksbrain\Documents\Code_Projects\maestro\maestor01\Lib\site-packages\anthropic_base_client.py", line 1019, in _request
raise self._make_status_error_from_response(err.response) from None
anthropic.BadRequestError: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages: text content blocks must be non-empty'}}
PS C:\Users\Spocksbrain\Documents\Code_Projects\maestro>

@awm19delta
Copy link

awm19delta commented May 30, 2024

I'm having this same issue repeatedly, trying to tweak the code but my skills are limited. It happens if there is no continuation prompt and/or when the orchestrator goes back to the sub-agent (I think). I can't seem to get past it.

@kkeeling
Copy link

kkeeling commented Jun 15, 2024

Try adding this error handling to maestro.py:

if not messages or not system_message:
        console.print("[bold red]Error:[/bold red] Messages or system message is empty, cannot proceed with creating the message.")
        return None

try:
    haiku_response = client.messages.create(
        model=SUB_AGENT_MODEL,
        max_tokens=4096,
        messages=messages,
        system=system_message
    )
    if not haiku_response.content:
        raise ValueError("No content in response")
except Exception as e:
    console.print(f"[bold red]Error:[/bold red] Failed to receive a valid response from the sub-agent. {str(e)}")
    return None

You wanna add this code around line 117, where the code is sending the a message to the sub-agent. The code there looks like this:

haiku_response = client.messages.create(
    model=SUB_AGENT_MODEL,
    max_tokens=4096,
    messages=messages,
    system=system_message
)

...and doesn't have any error handling. The code I pasted just adds error handling.

I just started looking at this project so I don't have the full context of what happens when you return None from this function, but for now it stopped the unhandled exception error. Be on the look out for other side effects.

@innerwestsoul
Copy link

I have this same issue. Causing me to chew through token credits :(

File "/Users/leon/Projects/External/maestro/maestro.py", line 245, in
sub_task_result = haiku_sub_agent(sub_task_prompt, search_query, haiku_tasks, use_search)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/leon/Projects/External/maestro/maestro.py", line 118, in haiku_sub_agent
haiku_response = client.messages.create(
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/leon/Projects/searchbot/searchbot/lib/python3.12/site-packages/anthropic/_utils/_utils.py", line 277, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/leon/Projects/searchbot/searchbot/lib/python3.12/site-packages/anthropic/resources/messages.py", line 904, in create
return self._post(
^^^^^^^^^^^
File "/Users/leon/Projects/searchbot/searchbot/lib/python3.12/site-packages/anthropic/_base_client.py", line 1249, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/leon/Projects/searchbot/searchbot/lib/python3.12/site-packages/anthropic/_base_client.py", line 931, in request
return self._request(
^^^^^^^^^^^^^^
File "/Users/leon/Projects/searchbot/searchbot/lib/python3.12/site-packages/anthropic/_base_client.py", line 1029, in _request
raise self._make_status_error_from_response(err.response) from None
anthropic.BadRequestError: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages: text content blocks must be non-empty'}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants