Skip to content

feat: add optional wrapper parameter to Session methods#2488

Open
Limitless2023 wants to merge 2 commits intoopenai:mainfrom
Limitless2023:feat/add-wrapper-to-session-methods
Open

feat: add optional wrapper parameter to Session methods#2488
Limitless2023 wants to merge 2 commits intoopenai:mainfrom
Limitless2023:feat/add-wrapper-to-session-methods

Conversation

@Limitless2023
Copy link

Summary

Add optional parameter to Session protocol methods (, , , ) to allow custom sessions to access context data during history operations.

This enables custom sessions to make decisions based on agent context, such as storing agent-specific information during handoff.

Fixes #2072

Changes

  • Add optional parameter to:
    • protocol (session.py)
    • abstract class (session.py)
    • implementation (sqlite_session.py)
    • implementation (openai_conversations_session.py)
    • implementation (openai_responses_compaction_session.py)

Test Plan

Existing tests should pass since the new parameter is optional with a default value of , maintaining backward compatibility.

Add optional RunContextWrapper parameter to Session protocol methods
(get_items, add_items, pop_item, clear_session) to allow custom sessions
to access context data during history operations.

This enables custom sessions to make decisions based on agent context,
such as storing agent-specific information during handoff.

Fixes openai#2072
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6cf6a5160

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Returns:
List of input items representing the conversation history
"""
return await self.underlying_session.get_items(limit, wrapper)

Choose a reason for hiding this comment

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

P1 Badge Preserve legacy session signatures when forwarding wrapper

OpenAIResponsesCompactionSession.get_items now forwards wrapper positionally via self.underlying_session.get_items(limit, wrapper), which passes an extra argument even when wrapper is None. Any existing underlying session that still implements the pre-change signature (e.g. get_items(limit=None)) will raise TypeError as soon as this wrapper calls into it, so this is not backward compatible despite wrapper being optional; the same unconditional extra-argument forwarding pattern is repeated in add_items, pop_item, and clear_session.

Useful? React with 👍 / 👎.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pass RunContextWrapper[T] to Session methods

2 participants