Skip to content

Pass context wrappers to session methods#2944

Draft
Bortlesboat wants to merge 1 commit intoopenai:mainfrom
Bortlesboat:codex/session-wrapper-2072
Draft

Pass context wrappers to session methods#2944
Bortlesboat wants to merge 1 commit intoopenai:mainfrom
Bortlesboat:codex/session-wrapper-2072

Conversation

@Bortlesboat
Copy link
Copy Markdown

Summary

  • add an optional keyword-only wrapper argument to the session protocol and built-in session implementations
  • thread the current RunContextWrapper through fresh runs, resumed runs, and rewind/save helpers
  • keep third-party session stores backward-compatible by only passing wrapper= when the implementation accepts it, with regression tests for both new and legacy sessions

Testing

  • uv run ruff format
  • uv run ruff check
  • uv run pyright src/agents/memory/session.py src/agents/run.py src/agents/run_internal/run_loop.py src/agents/run_internal/session_persistence.py src/agents/memory/openai_conversations_session.py src/agents/memory/openai_responses_compaction_session.py src/agents/memory/sqlite_session.py src/agents/extensions/memory/advanced_sqlite_session.py src/agents/extensions/memory/async_sqlite_session.py src/agents/extensions/memory/dapr_session.py src/agents/extensions/memory/encrypt_session.py src/agents/extensions/memory/mongodb_session.py src/agents/extensions/memory/redis_session.py src/agents/extensions/memory/sqlalchemy_session.py examples/memory/file_session.py tests/test_agent_as_tool.py tests/test_agent_runner.py tests/test_agent_runner_streamed.py tests/test_session.py tests/test_session_wrapper.py tests/utils/simple_session.py
  • uv run mypy src/agents/memory/session.py examples/memory/file_session.py tests/test_session_wrapper.py tests/test_session.py
  • uv run pytest tests/test_session_wrapper.py tests/utils/test_simple_session.py tests/test_session.py -k "session_add_items_exception_propagates_in_streamed or test_prepare_input_with_session_passes_wrapper_to_get_items or test_save_result_to_session_passes_wrapper_to_add_items or test_rewind_session_items_passes_wrapper_to_pop_and_cleanup or test_session_helpers_remain_compatible_with_legacy_sessions or test_runner_passes_context_wrapper_to_session_methods"
  • uv run pytest tests/test_agent_runner.py -k "wait_for_session_cleanup_retries_after_get_items_error or save_result_to_session_counts_sanitized_openai_items"
  • uv run pytest tests/test_agent_runner_streamed.py -k "stream_input_persistence_strips_ids_for_openai_conversation_session"
  • uv run python -m py_compile src/agents/memory/session.py src/agents/run.py src/agents/run_internal/run_loop.py src/agents/run_internal/session_persistence.py examples/memory/file_session.py tests/test_session_wrapper.py tests/test_session.py tests/test_agent_runner.py tests/test_agent_runner_streamed.py tests/utils/simple_session.py

Notes

  • uv run mypy . --exclude site and uv run pyright --project pyrightconfig.json still report pre-existing baseline issues in optional-dependency example/test modules and sandbox typing; this patch removes the new session-wrapper-specific typing failures.

Closes #2072

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

1 participant