databricks-openai: Add LakebaseSession Class that follows the Session protocol for Memory Management #240
+856
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Custom Session Implementation for short-term / long term memory on Databricks with connection pooling/token caching and rotation handled with LakebasePool capabilities
You can implement your own session memory by creating a class that follows the Session protocol:
https://openai.github.io/openai-agents-python/sessions/#custom-session-implementations
More on Session protocol:
https://openai.github.io/openai-agents-python/ref/memory/session/#agents.memory.session.Session
Before:
By using LakebasePool in our custom Session class implementation, we do not need to create a SQLAlchemy engine from the OpenAI Agents SDK example and can leverage the token caching/connection pooling logic Lakebase Pool offers already. Our Session class will have a cached pool associated with each Session instance so there aren't new pools created per session/user does not have to manage the pool
local testing + app testing
Notebook with smoke tests, CRUD operations tests, and integration tests:
https://eng-ml-agent-platform.staging.cloud.databricks.com/editor/notebooks/1816672511960993?o=2850744067564480#command/8078768795088187
App: https://eng-ml-agent-platform.staging.cloud.databricks.com/apps/j-openai-stateful?o=2850744067564480
Ensuring agent messages are logged in lakebase instance:

Unit tests:
python -m pytest integrations/openai/tests/unit_tests/test_session.py -v