aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaheshtheDev <[email protected]>2026-01-23 03:15:39 +0000
committerMaheshtheDev <[email protected]>2026-01-23 03:15:39 +0000
commit0853bc86cb210e07799ad7992460c48e53a25582 (patch)
tree79064e7e03ad118aa8805bb387e10db34a654c1e
parentdocs: gmail connector (#690) (diff)
downloadsupermemory-0853bc86cb210e07799ad7992460c48e53a25582.tar.xz
supermemory-0853bc86cb210e07799ad7992460c48e53a25582.zip
feat: tools package strict mode for openai models (#699)01-22-feat_tools_package_strict_mode_for_openai_models
-rw-r--r--packages/tools/README.md33
-rw-r--r--packages/tools/src/ai-sdk.ts31
-rw-r--r--packages/tools/src/types.ts15
3 files changed, 69 insertions, 10 deletions
diff --git a/packages/tools/README.md b/packages/tools/README.md
index e859ede7..a2390ad7 100644
--- a/packages/tools/README.md
+++ b/packages/tools/README.md
@@ -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
diff --git a/packages/tools/src/ai-sdk.ts b/packages/tools/src/ai-sdk.ts
index 0f2d5fe0..b931d325 100644
--- a/packages/tools/src/ai-sdk.ts
+++ b/packages/tools/src/ai-sdk.ts
@@ -20,6 +20,7 @@ export const searchMemoriesTool = (
})
const containerTags = getContainerTags(config)
+ const strict = config?.strict ?? false
return tool({
description: TOOL_DESCRIPTIONS.searchMemories,
@@ -27,16 +28,26 @@ export const searchMemoriesTool = (
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,
diff --git a/packages/tools/src/types.ts b/packages/tools/src/types.ts
index dfff0f00..9d05f6f1 100644
--- a/packages/tools/src/types.ts
+++ b/packages/tools/src/types.ts
@@ -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
}