Skip to content

Conversation

@tharindud
Copy link
Contributor

@tharindud tharindud commented Jan 30, 2026

Description

This PR make the following changes to the Session implementation.

  • Agent invocation on Runtime is asyncio friendly and makes sure invocations run in coroutines concurrently while making sure invocations for the same session runs serially
  • Refactoring and cleaning up Session implementation
  • Add unit tests to bring code coverage of Session class to 100%
  • Some APIs in Session have been changed and previous ones have been marked as deprecated (but still works)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update
  • CI/CD update
  • Other (please describe):

Changes Made

  • Cache keys defined in Session have been replaced with the enumeration Session.Keys
  • Session.get_current_session_id() has been replaced with Session.current() that returns the current session directly
  • Session now includes a proper repr
  • Session can now support entry/exit semantics for async with that mark it as the current session for the coroutine and also acquire an async lock to force serial execution of coroutines related to the same session.
  • Session.get_all_keys() has been replaced by the producer Session.get_all() that support filtering of session data objects by durability and volatility making it easier for storage implementations as they do not have to check session data object keys and filter accordingly.
  • Current session API based on Session.set_context() and Session.reset_context() has been deprecated in favor of async with entry/exit semantics.
  • AgentService.run_multi() has been modified to just call Runtime.run() without session locking. Volatile cache clearing and storage updating has also been removed. These steps not execute within Runtime.run().

Testing

  • Unit tests pass locally
  • Integration tests pass locally
  • Manual testing completed
  • New tests added for changes

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

…y and runs in a serial manner

Signed-off-by: Tharindu Dissanayake <[email protected]>
Copilot AI review requested due to automatic review settings January 30, 2026 05:57
@tharindud tharindud marked this pull request as draft January 30, 2026 05:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the Session class to make agent invocations asyncio-friendly with serial execution guarantees per session through async context managers and locks.

Changes:

  • Introduced async context manager support (__aenter__/__aexit__) for Session with an asyncio lock to ensure serial execution per session
  • Replaced session cache key constants with Session.Keys enumeration
  • Added new Session.current() and Session.get_all() methods while deprecating older APIs (get_current_session_id(), get_all_keys(), set_context(), reset_context())
  • Updated storage implementations (Redis, DynamoDB) to use the new get_all(volatile=False) API
  • Modified Runtime.run() and AuxiliaryCache methods to use the new session context management

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
ak-py/src/agentkernel/core/base.py Core refactoring: Added async context manager, Keys enum, new session methods, deprecated old APIs
ak-py/src/agentkernel/core/runtime.py Updated to use async with session pattern and new Session.current() API
ak-py/src/agentkernel/core/service.py Bug: Uses synchronous with instead of async with for session
ak-py/src/agentkernel/core/session/redis.py Updated store() to use new get_all(volatile=False) API
ak-py/src/agentkernel/core/session/dynamodb.py Updated store() to use new get_all(volatile=False) API
ak-py/src/agentkernel/framework/openai/openai.py Removed SessionABC inheritance from OpenAISession
ak-py/tests/test_session.py Added tests for new APIs, repr, get_all filtering; contains identity comparison bugs
ak-py/tests/test_runtime.py Updated tests to use new async with pattern and error messages

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings January 30, 2026 13:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

… serial access verification

Signed-off-by: Tharindu Dissanayake <[email protected]>
Signed-off-by: Tharindu Dissanayake <[email protected]>
Copilot AI review requested due to automatic review settings January 30, 2026 14:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Tharindu Dissanayake <[email protected]>
@tharindud tharindud marked this pull request as ready for review January 30, 2026 14:29
Copilot AI review requested due to automatic review settings January 30, 2026 14:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants