Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DanieleMorotti
Copy link
Contributor

Summary

Introduced the RunErrorDetails object to get partial results from a run interrupted by MaxTurnsExceeded exception. In this proposal the RunErrorDetails object contains all the fields from RunResult with final_output set to None and output_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 of agents/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

  • I've added new tests (if relevant)
  • I've added/updated the relevant documentation
  • [ ✅] I've run make lint and make format
  • [ ✅] I've made sure tests pass

@@ -1,7 +1,8 @@
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional
Copy link
Collaborator

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

@@ -244,3 +248,15 @@ def _cleanup_tasks(self):

def __str__(self) -> str:
return pretty_print_run_result_streaming(self)

@dataclass
class RunErrorDetails(RunResultBase):
Copy link
Collaborator

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.

Comment on lines 211 to 220
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
)
Copy link
Collaborator

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

@DanieleMorotti
Copy link
Contributor Author

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

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

Successfully merging this pull request may close these issues.

2 participants