chore: import upstream snapshot with attribution
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
import { isRecordLike } from '@sim/utils/object'
|
||||
import type { Mem0Response, Mem0SearchMemoriesParams } from '@/tools/mem0/types'
|
||||
import { SEARCH_RESULT_OUTPUT_PROPERTIES } from '@/tools/mem0/types'
|
||||
import type { JsonRecord } from '@/tools/mem0/utils'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
const getSearchResults = (data: unknown): JsonRecord[] => {
|
||||
if (!isRecordLike(data) || !Array.isArray(data.results)) return []
|
||||
return data.results.filter(isRecordLike)
|
||||
}
|
||||
|
||||
const getString = (value: unknown): string | undefined =>
|
||||
typeof value === 'string' ? value : undefined
|
||||
|
||||
const getStringArray = (value: unknown): string[] | undefined =>
|
||||
Array.isArray(value)
|
||||
? value.filter((item): item is string => typeof item === 'string')
|
||||
: undefined
|
||||
|
||||
const getNumber = (value: unknown, fallback = 0): number =>
|
||||
typeof value === 'number' ? value : fallback
|
||||
|
||||
/**
|
||||
* Search Memories Tool
|
||||
* @see https://docs.mem0.ai/api-reference/memory/search-memories
|
||||
*/
|
||||
export const mem0SearchMemoriesTool: ToolConfig<Mem0SearchMemoriesParams, Mem0Response> = {
|
||||
id: 'mem0_search_memories',
|
||||
name: 'Search Memories',
|
||||
description: 'Search for memories in Mem0 using semantic search',
|
||||
version: '1.0.0',
|
||||
|
||||
params: {
|
||||
userId: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'User ID to search memories for (e.g., "user_123", "alice@example.com")',
|
||||
},
|
||||
query: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Search query to find relevant memories (e.g., "What are my favorite foods?")',
|
||||
},
|
||||
limit: {
|
||||
type: 'number',
|
||||
required: false,
|
||||
default: 10,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Maximum number of results to return (e.g., 10, 50, 100)',
|
||||
},
|
||||
apiKey: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-only',
|
||||
description: 'Your Mem0 API key',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: 'https://api.mem0.ai/v3/memories/search/',
|
||||
method: 'POST',
|
||||
headers: (params) => ({
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Token ${params.apiKey}`,
|
||||
}),
|
||||
body: (params) => {
|
||||
return {
|
||||
query: params.query,
|
||||
filters: {
|
||||
user_id: params.userId.trim(),
|
||||
},
|
||||
top_k: Number(params.limit || 10),
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: async (response): Promise<Mem0Response> => {
|
||||
const data = await response.json()
|
||||
const searchResults = getSearchResults(data).map((result) => ({
|
||||
id: getString(result.id) ?? '',
|
||||
memory: getString(result.memory) ?? '',
|
||||
user_id: getString(result.user_id),
|
||||
agent_id: getString(result.agent_id),
|
||||
app_id: getString(result.app_id),
|
||||
run_id: getString(result.run_id),
|
||||
hash: getString(result.hash),
|
||||
metadata: isRecordLike(result.metadata) ? result.metadata : undefined,
|
||||
categories: getStringArray(result.categories),
|
||||
created_at: getString(result.created_at),
|
||||
updated_at: getString(result.updated_at),
|
||||
score: getNumber(result.score),
|
||||
}))
|
||||
const ids = searchResults.map((result) => result.id).filter(Boolean)
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
searchResults,
|
||||
ids,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
outputs: {
|
||||
searchResults: {
|
||||
type: 'array',
|
||||
description: 'Array of search results with memory data and similarity scores',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: SEARCH_RESULT_OUTPUT_PROPERTIES,
|
||||
},
|
||||
},
|
||||
ids: {
|
||||
type: 'array',
|
||||
description: 'Array of memory IDs found in the search results',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user