Doriandarko / maestro

A framework for Claude Opus to intelligently orchestrate subagents.
3.49k stars 569 forks source link

No error handling around empty messages #36

Open spocksbrain opened 1 month ago

spocksbrain commented 1 month ago

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 commented 1 month ago

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 commented 2 weeks ago

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 commented 1 week ago

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'}}