Expand description
§agent-framework-redis
Redis-backed HistoryProvider
and ContextProvider for
agent-framework-rs, porting agent_framework_redis from the Python
Agent Framework.
RedisChatMessageStore— one RedisLISTper session, JSON-serialized messages, optional automatic trimming. A close mirror of the PythonRedisChatMessageStore, adapted to theHistoryProvidercontract (before_run/after_run) now that conversation history lives in a context provider rather than on the session/thread itself.RedisContextProvider— scoped long-term memory storage/retrieval. Ports the PythonRedisProvider’s scoping semantics (application/agent/user/thread id). When the connected server has RediSearch loaded (Redis Stack), retrieval is backed by a realFT.SEARCHBM25 full-text index; otherwise it falls back to aSCAN+token-match path over plain Redis. Vector/hybrid search is not ported — see thecontext_providermodule docs for the full picture.
Both types connect lazily: constructing them only parses the Redis URL
(via redis::Client::open); the actual
MultiplexedConnection is
established on the first call that needs it.
use agent_framework_core::prelude::*;
use agent_framework_redis::{RedisChatMessageStore, RedisContextProvider};
use std::sync::Arc;
let store = RedisChatMessageStore::new("redis://127.0.0.1:6379", None)?
.with_max_messages(200);
let memory = RedisContextProvider::new("redis://127.0.0.1:6379")?.with_user_id("user-42");
let agent = Agent::builder(client)
.instructions("You are a helpful assistant.")
.context_provider(Arc::new(memory))
.build();
let mut session = AgentSession::new().with_context_providers(vec![Arc::new(store)]);
let response = agent
.run(vec![Message::user("Hello!")], Some(&mut session))
.await?;
println!("{}", response.text());Re-exports§
pub use chat_message_store::RedisChatMessageStore;pub use chat_message_store::DEFAULT_KEY_PREFIX as DEFAULT_STORE_KEY_PREFIX;pub use context_provider::RedisContextProvider;pub use context_provider::DEFAULT_CONTEXT_PROMPT;pub use context_provider::DEFAULT_KEY_PREFIX as DEFAULT_PROVIDER_KEY_PREFIX;pub use context_provider::DEFAULT_LIMIT;
Modules§
- chat_
message_ store - A Redis-backed
HistoryProvider: conversation history stored in a RedisLIST. - context_
provider - A
ContextProviderthat stores and retrieves conversation memories in Redis, scoped by application/agent/user/thread id.