Python: Fix Redis samples: add sessions, use configurable URL, fix API changes#4031
Python: Fix Redis samples: add sessions, use configurable URL, fix API changes#4031giles17 wants to merge 5 commits intomicrosoft:mainfrom
Conversation
- Add explicit session creation and pass session to agent.run() calls so Redis context provider can properly scope storage/retrieval - Replace hardcoded redis://localhost:6379 URLs with REDIS_URL env var - Fix alpha -> linear_alpha parameter rename in HybridQuery - Fix SessionContext usage to use input_messages constructor param - Remove obsolete scope_to_per_operation_thread_id parameter Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Pull request overview
This PR fixes the Redis context provider samples to work with the current Agent Framework APIs. The samples were broken due to several API changes: the removal of scope_to_per_operation_thread_id parameter from RedisContextProvider, the requirement that SessionContext must be initialized with input_messages, and the redisvl library's change from alpha to linear_alpha parameter in HybridQuery.
Changes:
- Added explicit session creation and passing sessions to agent.run() calls in all sample files
- Introduced configurable REDIS_URL environment variable in redis_basics.py (replacing hardcoded localhost URLs)
- Fixed SessionContext initialization to use
input_messagesparameter instead of callingextend_messages() - Updated HybridQuery parameter from
alphatolinear_alphain the Redis context provider implementation
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| python/samples/02-agents/context_providers/redis/redis_sessions.py | Removed obsolete scope_to_per_operation_thread_id parameter and added session creation/usage for all agent.run() calls |
| python/samples/02-agents/context_providers/redis/redis_conversation.py | Added session creation and passing to agent.run() calls |
| python/samples/02-agents/context_providers/redis/redis_basics.py | Added REDIS_URL environment variable, fixed SessionContext API usage, and added session handling |
| python/samples/02-agents/context_providers/redis/azure_redis_conversation.py | Added session creation with persistent session ID and passing to agent.run() calls |
| python/packages/redis/agent_framework_redis/_context_provider.py | Fixed HybridQuery parameter name from alpha to linear_alpha for redisvl API compatibility |
python/samples/02-agents/context_providers/redis/redis_conversation.py
Outdated
Show resolved
Hide resolved
…ll Redis samples All Redis samples now use REDIS_URL environment variable (defaults to redis://localhost:6379) instead of hardcoded URLs. This makes it easy to point samples at remote or authenticated Redis instances. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Only the 4 samples in 02-agents/context_providers/redis/ should have the REDIS_URL env var change. Reverting the other files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pull request was closed
| # Use a fixed session ID so Redis history persists across separate program runs | ||
| session = agent.create_session(session_id="redis-demo-session") |
There was a problem hiding this comment.
Should this example work without session? If you create and re-use the same session, the history should be already preserved. I think the main point of using context provider is the ability to inject the same context across multiple sessions.
Summary
Fixes Redis context provider and samples to work with current APIs.
Changes
agent.run()so the Redis context provider can scope storage/retrieval per conversationredis://localhost:6379with configurableREDIS_URLenv var (defaults to localhost)alpha→linear_alphaparameter rename inHybridQuery(redisvl API change)SessionContext(input_messages=...)constructor instead of removedextend_messages()scope_to_per_operation_thread_idparameter fromRedisContextProvider