langmem0 Modules¶
ChatOpenAI¶
- pydantic model langmem0.ChatOpenAI[source]¶
Chat model that uses the Mem0-based OpenAI API.
- Config:
extra: str = ignore
protected_namespaces: tuple = ()
arbitrary_types_allowed: bool = True
populate_by_name: bool = True
validate_by_alias: bool = True
validate_by_name: bool = True
- Validators:
with_mem0»all fields
- field mem0: dict[str, Any] [Required]¶
The Mem0 configuration to use.
- field user_id: str | None = None¶
The user ID to use for the Mem0 API.
Mem0Middleware¶
- class langmem0.Mem0Middleware(config)[source]¶
Bases:
AgentMiddlewareMiddleware for integrating Mem0 memory with LangChain agents.
This middleware automatically stores conversations and retrieves relevant memories during model calls to provide personalized responses.
- __init__(config)[source]¶
Initialize the Mem0 middleware.
- Parameters:
config (dict[str, Any]) – Mem0 configuration dictionary.
- async aafter_agent(state, runtime)[source]¶
Async handler called after agent execution.
- Parameters:
state (AgentState) – The agent state.
runtime (Runtime) – The runtime context.
- Returns:
Returns None if user ID is not found.
- Return type:
None
- after_agent(state, runtime)[source]¶
Handler called after agent execution.
- Parameters:
state (AgentState) – The agent state.
runtime (Runtime) – The runtime context.
- Returns:
Returns None if user ID is not found.
- Return type:
None