Skip to main content
Glama

get_memories

Retrieve stored memories using structured filters for specific users, agents, or time periods, with pagination support for browsing results.

Instructions

Page through memories using filters instead of search.

    Use filters to list specific memories. Common filter patterns:
    - Single user: {"AND": [{"user_id": "john"}]}
    - Agent memories: {"AND": [{"agent_id": "agent_name"}]}
    - Recent memories: {"AND": [{"user_id": "john"}, {"created_at": {"gte": "2024-01-01"}}]}
    - Multiple users: {"AND": [{"user_id": {"in": ["john", "jane"]}}]}

    Pagination: Use page (1-indexed) and page_size for browsing results.
    user_id is automatically added to filters if not provided.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filtersNoStructured filters; user_id injected automatically.
pageNo1-indexed page number when paginating.
page_sizeNoNumber of memories per page (default 10).
enable_graphNoSet true only if the caller explicitly wants graph-derived memories.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'get_memories' tool. It prepares the payload using GetMemoriesArgs, injects default user filters, and calls the Mem0 client's get_all method.
    def get_memories(
        filters: Annotated[
            Optional[Dict[str, Any]],
            Field(default=None, description="Structured filters; user_id injected automatically."),
        ] = None,
        page: Annotated[
            Optional[int], Field(default=None, description="1-indexed page number when paginating.")
        ] = None,
        page_size: Annotated[
            Optional[int], Field(default=None, description="Number of memories per page (default 10).")
        ] = None,
        enable_graph: Annotated[
            Optional[bool],
            Field(
                default=None,
                description="Set true only if the caller explicitly wants graph-derived memories.",
            ),
        ] = None,
        ctx: Context | None = None,
    ) -> str:
        """List memories via structured filters or pagination."""
    
        api_key, default_user, graph_default = _resolve_settings(ctx)
        args = GetMemoriesArgs(
            filters=filters,
            page=page,
            page_size=page_size,
            enable_graph=_default_enable_graph(enable_graph, graph_default),
        )
        payload = args.model_dump(exclude_none=True)
        payload["filters"] = _with_default_filters(default_user, payload.get("filters"))
        payload.setdefault("enable_graph", graph_default)
        client = _mem0_client(api_key)
        return _mem0_call(client.get_all, **payload)
  • Pydantic model defining the input schema for the get_memories tool, including filters, pagination, and graph options.
    class GetMemoriesArgs(BaseModel):
        filters: Optional[Dict[str, Any]] = Field(
            None, description="Structured filters; user_id injected automatically."
        )
        page: Optional[int] = Field(None, description="1-indexed page number.")
        page_size: Optional[int] = Field(None, description="Number of memories per page.")
        enable_graph: Optional[bool] = Field(
            None, description="Set True only when the user wants graph knowledge."
        )
  • The @server.tool decorator registers the get_memories function as an MCP tool with its description.
    @server.tool(
        description="""Page through memories using filters instead of search.
    
        Use filters to list specific memories. Common filter patterns:
        - Single user: {"AND": [{"user_id": "john"}]}
        - Agent memories: {"AND": [{"agent_id": "agent_name"}]}
        - Recent memories: {"AND": [{"user_id": "john"}, {"created_at": {"gte": "2024-01-01"}}]}
        - Multiple users: {"AND": [{"user_id": {"in": ["john", "jane"]}}]}
    
        Pagination: Use page (1-indexed) and page_size for browsing results.
        user_id is automatically added to filters if not provided.
        """
    )
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: pagination mechanics (page and page_size), automatic user_id injection into filters, and the default page_size of 10. However, it doesn't mention rate limits, authentication requirements, or error conditions, leaving some gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the core purpose, followed by usage guidelines and parameter semantics. Every sentence earns its place by providing essential information without redundancy, making it efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (4 parameters, no annotations, but with an output schema), the description is largely complete. It covers purpose, usage, key behaviors, and parameter details. The presence of an output schema means return values don't need explanation, but minor gaps remain in behavioral aspects like error handling or advanced usage notes.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the baseline is 3. The description adds significant value by explaining the 'filters' parameter with concrete examples (e.g., single user, agent memories), clarifying that 'user_id is automatically added,' and noting pagination details. This enhances understanding beyond the schema's technical definitions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as 'Page through memories using filters instead of search,' which is a specific verb+resource+method combination. It distinguishes from sibling tools like 'search_memories' by emphasizing the filter-based approach versus search functionality.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool ('use filters to list specific memories') and implicitly contrasts it with 'search_memories' by stating 'instead of search.' It also offers common filter patterns as practical examples, helping the agent understand appropriate use cases.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/parthshr370/mem0_mcp_private'

If you have feedback or need assistance with the MCP directory API, please join our Discord server