Working Memory¶
Working Memory Agent for the Arshai framework.
This module provides an agent specialized in managing conversation working memory. It handles fetching conversation history, updating memory in storage systems, and generating memory summaries.
Classes¶
- class arshai.agents.hub.working_memory.WorkingMemoryAgent(llm_client, system_prompt=None, memory_manager=None, chat_history_client=None, **kwargs)[source]¶
Bases:
BaseAgentAgent specialized in managing conversation working memory.
This agent is responsible for maintaining and updating the working memory of conversations. It fetches conversation history, generates summaries, and stores updated memory in persistent storage.
Capabilities: - Fetches conversation history from chat history storage - Retrieves current working memory from storage (e.g., Redis) - Generates revised working memory based on new interactions - Stores updated memory for future reference
Requirements: - Memory manager for storage operations - Chat history client for conversation retrieval (optional)
Example
memory_manager = RedisMemoryManager(redis_client) agent = WorkingMemoryAgent(
llm_client, “You are a memory management assistant”, memory_manager=memory_manager
)
# Update memory for a conversation result = await agent.process(IAgentInput(
message=”User asked about product pricing”, metadata={“conversation_id”: “123”}
)) # Returns “success” if successful, or “error: <description>” if failed
- __init__(llm_client, system_prompt=None, memory_manager=None, chat_history_client=None, **kwargs)[source]¶
Initialize the working memory agent.
- Parameters:
llm_client (
ILLM) – The LLM client for generating memory updatessystem_prompt (
str) – Optional custom prompt (uses default if not provided)memory_manager (
IMemoryManager) – Memory manager for storage operationschat_history_client (
Any) – Optional client for fetching conversation history**kwargs – Additional configuration
- async process(input)[source]¶
Process memory update request.
This method: 1. Extracts conversation_id from metadata 2. Fetches current memory and history 3. Generates updated memory using LLM 4. Stores the updated memory
- Parameters:
input (
IAgentInput) – Input containing the new interaction and metadata with conversation_id- Returns:
- Status of the operation - “success” if successful,
”error: <description>” if failed, or None if no conversation_id
- Return type: