Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions packages/tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,45 @@ interface SupermemoryToolsConfig {
baseUrl?: string
containerTags?: string[]
projectId?: string
strict?: boolean
}
```

- **baseUrl**: Custom base URL for the supermemory API
- **containerTags**: Array of custom container tags (mutually exclusive with projectId)
- **projectId**: Project ID which gets converted to container tag format (mutually exclusive with containerTags)
- **strict**: Enable strict schema mode for OpenAI strict validation. When `true`, all schema properties are required (satisfies OpenAI strict mode). When `false` (default), optional fields remain optional for maximum compatibility with all models.

### OpenAI Strict Mode Compatibility

When using OpenAI-compatible providers with strict schema validation (e.g., OpenRouter with Azure OpenAI backend), enable strict mode to ensure all schema properties are included in the `required` array:

```typescript
import { searchMemoriesTool, addMemoryTool } from "@supermemory/tools/ai-sdk"
import { createOpenRouter } from "@openrouter/ai-sdk-provider"
import { streamText } from "ai"

const openrouter = createOpenRouter({ apiKey: process.env.OPENROUTER_API_KEY })

const tools = {
searchMemories: searchMemoriesTool(apiKey, {
containerTags: [userId],
strict: true // ✅ Required for OpenAI strict mode
}),
addMemory: addMemoryTool(apiKey, {
containerTags: [userId],
strict: true
}),
}

const result = streamText({
model: openrouter.chat("openai/gpt-5-nano"),
messages: [...],
tools,
})
```

Without `strict: true`, optional fields like `includeFullDocs` and `limit` won't be in the `required` array, which will cause validation errors with OpenAI strict mode.

### withSupermemory Middleware Options

Expand Down
31 changes: 21 additions & 10 deletions packages/tools/src/ai-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,34 @@ export const searchMemoriesTool = (
})

const containerTags = getContainerTags(config)
const strict = config?.strict ?? false

return tool({
description: TOOL_DESCRIPTIONS.searchMemories,
inputSchema: z.object({
informationToGet: z
.string()
.describe(PARAMETER_DESCRIPTIONS.informationToGet),
includeFullDocs: z
.boolean()
.optional()
.default(DEFAULT_VALUES.includeFullDocs)
.describe(PARAMETER_DESCRIPTIONS.includeFullDocs),
limit: z
.number()
.optional()
.default(DEFAULT_VALUES.limit)
.describe(PARAMETER_DESCRIPTIONS.limit),
includeFullDocs: strict
? z
.boolean()
.default(DEFAULT_VALUES.includeFullDocs)
.describe(PARAMETER_DESCRIPTIONS.includeFullDocs)
: z
.boolean()
.optional()
.default(DEFAULT_VALUES.includeFullDocs)
.describe(PARAMETER_DESCRIPTIONS.includeFullDocs),
limit: strict
? z
.number()
.default(DEFAULT_VALUES.limit)
.describe(PARAMETER_DESCRIPTIONS.limit)
: z
.number()
.optional()
.default(DEFAULT_VALUES.limit)
.describe(PARAMETER_DESCRIPTIONS.limit),
}),
execute: async ({
informationToGet,
Expand Down
15 changes: 15 additions & 0 deletions packages/tools/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
* Only one of `projectId` or `containerTags` can be provided.
*/
export interface SupermemoryToolsConfig {
/**
* Custom base URL for the supermemory API
*/
baseUrl?: string
/**
* Array of custom container tags (mutually exclusive with projectId)
*/
containerTags?: string[]
/**
* Project ID which gets converted to container tag format (mutually exclusive with containerTags)
*/
projectId?: string
/**
* Enable strict schema mode for OpenAI strict validation.
* When true, all schema properties are required (satisfies OpenAI strict mode).
* When false (default), optional fields remain optional for maximum compatibility.
*/
strict?: boolean
}
Loading