-
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?
Changes from 1 commit
c1e43a6
387b5eb
7989e0d
f083c48
6736687
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,11 @@ | |
from .run_context import RunContextWrapper | ||
from .stream_events import StreamEvent | ||
from .tracing import Trace | ||
from .util._pretty_print import pretty_print_result, pretty_print_run_result_streaming | ||
from .util._pretty_print import ( | ||
pretty_print_result, | ||
pretty_print_run_error_details, | ||
pretty_print_run_result_streaming, | ||
) | ||
|
||
if TYPE_CHECKING: | ||
from ._run_impl import QueueCompleteSentinel | ||
|
@@ -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 commentThe 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, |
||
_last_agent: Agent[Any] | ||
|
||
@property | ||
def last_agent(self) -> Agent[Any]: | ||
"""The last agent that was run.""" | ||
return self._last_agent | ||
|
||
def __str__(self) -> str: | ||
return pretty_print_run_error_details(self) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ | |
from .model_settings import ModelSettings | ||
from .models.interface import Model, ModelProvider | ||
from .models.multi_provider import MultiProvider | ||
from .result import RunResult, RunResultStreaming | ||
from .result import RunErrorDetails, RunResult, RunResultStreaming | ||
from .run_context import RunContextWrapper, TContext | ||
from .stream_events import AgentUpdatedStreamEvent, RawResponsesStreamEvent | ||
from .tool import Tool | ||
|
@@ -208,7 +208,20 @@ async def run( | |
data={"max_turns": max_turns}, | ||
), | ||
) | ||
raise MaxTurnsExceeded(f"Max turns ({max_turns}) exceeded") | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. it might make more sense to create this in the outermost |
||
raise MaxTurnsExceeded( | ||
f"Max turns ({max_turns}) exceeded", | ||
run_error_details | ||
) | ||
|
||
logger.debug( | ||
f"Running agent {current_agent.name} (turn {current_turn})", | ||
|
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 doerror_details: ErrorDetails | None