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
5 changes: 5 additions & 0 deletions .changeset/rich-avocados-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"agents-sdk": patch
---

Replace discriminatedUnion with simple object for Gemini models
6 changes: 3 additions & 3 deletions examples/playground/src/agents/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ Input to parse: "${event.input}"`,
}
const schedule = await this.schedule(
when.type === "scheduled"
? when.date
? when.date!
: when.type === "delayed"
? when.delayInSeconds
: when.cron,
? when.delayInSeconds!
: when.cron!,
"onTask",
description
);
Expand Down
29 changes: 18 additions & 11 deletions packages/agents/evals/scheduling.eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {

const model = openai("gpt-4o");
// const model = google("gemini-2.0-pro-exp-02-05");
// const model = google("gemini-2.0-flash");
// const model = google("gemini-1.5-pro");
// const model = anthropic("claude-3-5-sonnet-20240620"); // also disable mode: "json"

function assert(condition: unknown, message: string): asserts condition {
Expand Down Expand Up @@ -39,7 +41,7 @@ const getsDetail = createScorer<string, Schedule>({
output.when.type === "scheduled",
"Output is not a scheduled task"
);
return output.when.date.getTime() === expected.when.date.getTime()
return output.when?.date?.getTime() === expected.when?.date?.getTime()
? 1
: 0;
}
Expand Down Expand Up @@ -323,18 +325,23 @@ evalite<string, Schedule>("Evals for scheduling", {
},
// The task to perform
task: async (input) => {
const result = await generateObject({
model,
// mode: "json",
// schemaName: "task",
// schemaDescription: "A task to be scheduled",
schema: unstable_scheduleSchema, // <- the shape of the object that the scheduler expects
maxRetries: 5,
prompt: `${unstable_getSchedulePrompt({ date: new Date() })}
try {
const result = await generateObject({
model,
// mode: "json",
// schemaName: "task",
// schemaDescription: "A task to be scheduled",
schema: unstable_scheduleSchema, // <- the shape of the object that the scheduler expects
maxRetries: 5,
prompt: `${unstable_getSchedulePrompt({ date: new Date() })}

Input to parse: "${input}"`,
});
return result.object;
});
return result.object;
} catch (error) {
console.error(error);
throw error;
}
},
scorers: [getsType, getsDetail, getsDescription],
});
48 changes: 23 additions & 25 deletions packages/agents/src/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,27 @@ Example outputs:

export const unstable_scheduleSchema = z.object({
description: z.string().describe("A description of the task"),
when: z.discriminatedUnion("type", [
z
.object({
type: z.literal("scheduled"),
date: z.coerce.date(),
})
.describe("A scheduled task for a given date and time"),
z
.object({
type: z.literal("delayed"),
delayInSeconds: z.number(),
})
.describe("A delayed task in seconds"),
z
.object({
type: z.literal("cron"),
cron: z.string(),
})
.describe("A cron pattern"),
z
.object({
type: z.literal("no-schedule"),
})
.describe("No timing information, just a description of the task"),
]),
when: z.object({
type: z
.enum(["scheduled", "delayed", "cron", "no-schedule"])
.describe("The type of scheduling details"),
date: z.coerce
.date()
.optional()
.describe(
"execute task at the specified date and time (only use if the type is scheduled)"
),
delayInSeconds: z
.number()
.optional()
.describe(
"execute task after a delay in seconds (only use if the type is delayed)"
),
cron: z
.string()
.optional()
.describe(
"execute task on a recurring interval specified as cron syntax (only use if the type is cron)"
),
}),
});