Skip to content

agent_id filter not working in v2 API (get_all and search) #3773

@feiwofeifeixiaowo

Description

@feiwofeifeixiaowo

Description

The agent_id filter doesn't work in v2 API for get_all and search operations, even though the documentation states it should.

Documentation reference: https://docs.mem0.ai/platform/features/v2-memory-filters#missing-results-with-agent-id

Steps to Reproduce

from mem0 import AsyncMemoryClient

client = AsyncMemoryClient(api_key="...")

# 1. Add memory with agent_id
result = await client.add(
    messages=[{"role": "user", "content": "Test memory"}],
    user_id="test_user_123",
    agent_id="test_agent_456",
    run_id="test_run_789",
    infer=False,
)
# ✅ Memory created successfully

# 2. Try to filter by agent_id
filters = {"AND": [{"user_id": "test_user_123"}, {"agent_id": "test_agent_456"}]}
results = await client.get_all(filters=filters)
# ❌ Returns 0 results

# 3. Try wildcard agent_id (per documentation)
filters = {"AND": [{"user_id": "test_user_123"}, {"agent_id": "*"}]}
results = await client.get_all(filters=filters)
# ❌ Returns 0 results

# 4. Filter by run_id works correctly
filters = {"AND": [{"user_id": "test_user_123"}, {"run_id": "test_run_789"}]}
results = await client.get_all(filters=filters)
# ✅ Returns 1 result

Expected Behavior

According to the documentation, filtering by agent_id should return memories that were added with that agent_id. The wildcard {"agent_id": "*"} should return all memories with non-null agent_id values.

Actual Behavior

  • agent_id filter returns 0 results (both exact match and wildcard)
  • run_id filter works correctly
  • When retrieving the memory by ID, it shows agent_id is stored in metadata but not as a filterable field

Memory Structure Returned

{
    'id': '...',
    'memory': 'Test memory',
    'user_id': 'test_user_123',
    'session_id': 'test_run_789',  # run_id is mapped to session_id
    'metadata': {
        'agent_id': 'test_agent_456',  # agent_id only in metadata
        'run_id': 'test_run_789'
    },
    ...
}

Note: run_id is properly indexed as session_id, but agent_id appears to only be stored in metadata without indexing.

Environment

  • mem0 SDK version: 0.1.98 (latest)
  • Python version: 3.12
  • API: Platform API (api.mem0.ai)

Questions

  1. Is agent_id filtering currently supported in v2 API?
  2. If not, is this a planned feature?
  3. Should we use run_id as the primary scope identifier instead?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions