-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Added RunErrorDetails object for MaxTurnsExceeded exception #743
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
base: main
Are you sure you want to change the base?
Added RunErrorDetails object for MaxTurnsExceeded exception #743
Conversation
src/agents/exceptions.py
Outdated
@@ -1,7 +1,8 @@ | |||
from typing import TYPE_CHECKING | |||
from typing import TYPE_CHECKING, Optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of Optiona, you can from __future__ import annotations
then do error_details: ErrorDetails | None
src/agents/result.py
Outdated
@@ -244,3 +248,15 @@ def _cleanup_tasks(self): | |||
|
|||
def __str__(self) -> str: | |||
return pretty_print_run_result_streaming(self) | |||
|
|||
@dataclass | |||
class RunErrorDetails(RunResultBase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it makes sense to subclass RunResultBase. The error details and result can/should diverge - for example, final_output
doesn't make sense in error details, because by definition there is no error.
src/agents/run.py
Outdated
run_error_details = RunErrorDetails( | ||
input=original_input, | ||
new_items=generated_items, | ||
raw_responses=model_responses, | ||
final_output=None, | ||
input_guardrail_results=input_guardrail_results, | ||
output_guardrail_results=[], | ||
context_wrapper=context_wrapper, | ||
_last_agent=current_agent | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might make more sense to create this in the outermost try-catch
. You'll catch all exceptions there, so you can capture and re-raise
Hi, thanks for the suggestions. I should have implemented the requested changes, let me know if I understood correctly or I have to correct the code |
Summary
Introduced the
RunErrorDetails
object to get partial results from a run interrupted byMaxTurnsExceeded
exception. In this proposal theRunErrorDetails
object contains all the fields fromRunResult
withfinal_output
set toNone
andoutput_guardrail_results
set to an empty list. We can decide to return less information.@rm-openai At the moment the exception doesn't return the
RunErrorDetails
object for the streaming mode. Do you have any suggestions on how to deal with it? In the_check_errors
function ofagents/result.py
file.Test plan
I have not implemented any tests currently, but if needed I can implement a basic test to retrieve partial data.
Issue number
This PR is an attempt to solve issue #719
Checks
make lint
andmake format