Skip to content

Save session on turn rather than at final response #1550

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 3 commits into
base: main
Choose a base branch
from

Conversation

spokeydokeys
Copy link

@spokeydokeys spokeydokeys commented Aug 21, 2025

The current implementation of sessions saves the session on the final output. This works as a "memory" of previous full conversations, but does not work if you need access to the session during the turn. A use case for this is providing access to the full conversation to an agent-as-tool during the turn.

This PR updates the run and _start_streaming methods in run.py to save the session on each turn.

The basic flow is:

  • On completion start, save the input into the session.
  • After each turn, add only the turn results to the session.

Also included is an example file that shows the use of this pattern. It is an adapted version of the agents-as-tools example where a check agent is called within the same turn as the translation agents and examines their outputs via the conversation history, rather than as a generated input.

  • Current tests pass and I don't think an update to the tests is needed for this PR.
  • Documentation about sessions did not cover this case, but I felt it was implied that it would work. I think these changes bring the behavior in line with the documentation.
  • I have added an example that demonstrates it in action.

@spokeydokeys
Copy link
Author

Addresses issue #1551

@seratch seratch added bug Something isn't working feature:sessions labels Aug 21, 2025
@seratch seratch requested a review from rm-openai August 21, 2025 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature:sessions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants