Skip to main content

Crate agent_framework_redis

Crate agent_framework_redis 

Source
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 Redis LIST per session, JSON-serialized messages, optional automatic trimming. A close mirror of the Python RedisChatMessageStore, adapted to the HistoryProvider contract (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 Python RedisProvider’s scoping semantics (application/agent/user/thread id). When the connected server has RediSearch loaded (Redis Stack), retrieval is backed by a real FT.SEARCH BM25 full-text index; otherwise it falls back to a SCAN+token-match path over plain Redis. Vector/hybrid search is not ported — see the context_provider module 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 Redis LIST.
context_provider
A ContextProvider that stores and retrieves conversation memories in Redis, scoped by application/agent/user/thread id.