autogen icon indicating copy to clipboard operation
autogen copied to clipboard

[Issue]: no docs on how to catch executor exceptions (or if possible in "speaker_selection_method")

Open Morriz opened this issue 1 year ago • 2 comments

Describe the issue

When UserProxyAgent runs code generated by a "coder" agent it throws an exception when it is invalid code. How can we catch such exceptions (preferably in the speaker_selection_method function) so that we can let the previous agent (coder) retry?

Steps to reproduce

try the sample code on page https://microsoft.github.io/autogen/docs/topics/groupchat/customized_speaker_selection

when the code is not correct the chain fails and does not recover

Screenshots and logs

No response

Additional Information

No response

Morriz avatar Apr 26 '24 09:04 Morriz

Sry for being lazy and not reading well, but changing this line:

    ...
    elif last_speaker is executor:
        if messages[-1]["content"] == "exitcode: 1":
            # retrieve --(execution failed)--> retrieve
            return coder
    ...

to:

    ...
    elif last_speaker is executor:
        if messages[-1]["content"].startswith("exitcode: 1"):
            # retrieve --(execution failed)--> retrieve
            return coder
    ...

is surely helping out, as the latest version is obviously verbose and also prints the output...

Morriz avatar Apr 26 '24 10:04 Morriz

PR welcomes! We can add a test case for this.

ekzhu avatar Apr 27 '24 00:04 ekzhu