mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-05-19 16:13:19 +00:00
feat: tools package strict mode for openai models (#699)
This commit is contained in:
parent
0d82ac3238
commit
0853bc86cb
3 changed files with 69 additions and 10 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Add a link
Reference in a new issue