Skip to content

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.

Resolves #1551

@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
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to send this. At a glance, the changes look good, but we need unit tests verifying the patterns and we don't need the additional example.

@@ -0,0 +1,116 @@
import asyncio
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of having this example, we need unit tests verifying the pattern

@spokeydokeys
Copy link
Author

I removed the example and added a unit test to test_agent_runner.py.

There were a few linting and formatting issues that make lint and make check-format brought up that weren't in my changes, but I let ruff fix them and included them in the last commit. Happy to drop those if you'd rather leave them.

@spokeydokeys spokeydokeys requested a review from seratch August 26, 2025 23:08
@@ -84,6 +84,7 @@ class RealtimeModelInputAudioTranscriptionCompletedEvent:

type: Literal["input_audio_transcription_completed"] = "input_audio_transcription_completed"


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove these unrelated changes to make the review easier?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove these unrelated changes to make the review easier?

Of course! I removed the final commit that had all the make lint/check-format changes that weren't part of the bug fix.

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.

Session objects not updated until final output
2 participants