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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"dependencies": {
"@agentage/core": "^0.1.0",
"openai": "^6.15.0",
"zod": "4.3.6"
"zod": "^4.3.6"
},
"devDependencies": {
"@types/jest": "^30.0.0",
Expand Down
14 changes: 8 additions & 6 deletions packages/sdk/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
Tool,
} from '@agentage/core';
import OpenAI from 'openai';
import { toJSONSchema } from 'zod';
import type { ChatCompletionMessageParam } from 'openai/resources/chat/completions';
import {
MissingApiKeyError,
Expand Down Expand Up @@ -42,19 +43,20 @@ function convertSchemaToJsonSchema(schema: any): any {
const required: string[] = [];

for (const [key, value] of Object.entries(schema)) {
// Check if it's a Zod schema (has toJSONSchema method from Zod 4.x)
if (value && typeof value === 'object' && 'toJSONSchema' in value) {
// Check if it's a Zod schema (has _zod property in Zod 4.x)
if (value && typeof value === 'object' && ('_zod' in value || '_def' in value)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const jsonSchema = (value as any).toJSONSchema();
const jsonSchema = toJSONSchema(value as any);

// Extract the actual schema (remove top-level $schema if present)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { $schema, ...cleanSchema } = jsonSchema as Record<string, unknown>;
properties[key] = cleanSchema;

// Check if the field is optional
const def = (value as { _def?: { typeName?: string } })._def;
if (def?.typeName !== 'ZodOptional') {
// Check if the field is optional (Zod 4.x uses _zod.def.type)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const zodDef = (value as any)._zod?.def;
if (zodDef?.type !== 'optional') {
required.push(key);
}
} else {
Expand Down