Skip to content

Make intermediate results available when MaxTurnExceededException is thrown #719

Open
@chiehmin-wei

Description

@chiehmin-wei

Describe the feature

I want to access intermediate results when MaxTurnExceededException is thrown.

I have a workflow broken into 2 phases.
Phase 1 is investigation.
Phase 2 is writing up a report based on the investigation results.

I'm feeding the results of phase 1 into phase 2 like so:

result = Runner.run(investigation_agent, max_turns=5)
report = Runner.run(report_agent, result.to_input_list())

I want to limit the number of turns in Phase 1.
If a MaxTurnExceededException is thrown in Phase 1, I still want to make use of the available information in Phase 2.
Currently this doesn't seem possible to do. I have no way to access the intermediate results (tool calls, etc.) if I reach max turns in Phase 1.

Activity

rm-openai

rm-openai commented on May 20, 2025

@rm-openai
Collaborator

Yes we should indeed do this. Will try to get to it soon - as always, PR welcome from anyone

DanieleMorotti

DanieleMorotti commented on May 20, 2025

@DanieleMorotti
Contributor

I can have a look if @chiehmin-wei is not already working on it. How would you return / save the partial results?
In the Runner object?

rm-openai

rm-openai commented on May 21, 2025

@rm-openai
Collaborator

I think partial results are already built up in Runner, as you described; when the exception is raised, you can add a RunErrorDetails object with all that data

DanieleMorotti

DanieleMorotti commented on May 22, 2025

@DanieleMorotti
Contributor

Okay, so I have to create a new class RunErrorDetails and then pass the data in the MaxTurnsExceeded exception? Obviously adding this optional attribute to the exception

rm-openai

rm-openai commented on May 22, 2025

@rm-openai
Collaborator

yup!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @DanieleMorotti@chiehmin-wei@rm-openai

        Issue actions

          Make intermediate results available when `MaxTurnExceededException` is thrown · Issue #719 · openai/openai-agents-python