Use this file to discover all available pages before exploring further.
Agents can return structured, type-safe output by defining a Zod schema. This ensures responses conform to a specific format, making them easy to parse and use in your application.
const WebSearchPlanSchema = z.object({ searches: z.array( z.object({ reason: z .string() .describe('Your reasoning for why this search is important to the query.'), query: z .string() .describe('The search term to use for the web search.'), }) ).describe('A list of web searches to perform to best answer the query.'),});const planner = agent({ model: openai('gpt-4o'), name: 'PlannerAgent', output: WebSearchPlanSchema, prompt: instructions({ purpose: [ 'Given a query, come up with a set of web searches to perform.', ], routine: ['Output between 5 and 10 terms to query for.'], }),});const result = await generate(planner, 'Query: AI agents in production', {});const plan = result.output;// Type-safe accessplan.searches.forEach(search => { console.log(`Query: ${search.query}`); console.log(`Reason: ${search.reason}`);});
const ReportDataSchema = z.object({ short_summary: z .string() .describe('A short 2-3 sentence summary of the findings.'), markdown_report: z.string().describe('The final report'), follow_up_questions: z .array(z.string()) .describe('Suggested topics to research further'),});const writer = agent({ name: 'WriterAgent', model: openai('gpt-4o'), output: ReportDataSchema, prompt: instructions({ purpose: ['Write a cohesive report for a research query.'], routine: [ 'Come up with an outline', 'Generate the report in markdown', 'Aim for 5-10 pages, at least 1000 words', ], }),});
const FinancialSearchPlanSchema = z.object({ searches: z .array( z.object({ reason: z.string().describe('Why this search is relevant'), query: z.string().describe('The search term'), }) ) .describe('A list of searches to perform'),});const AnalysisSummarySchema = z.object({ summary: z.string().describe('Short text summary for this aspect'),});const FinancialReportDataSchema = z.object({ short_summary: z.string().describe('A short 2-3 sentence executive summary'), markdown_report: z.string().describe('The full markdown report'), follow_up_questions: z .array(z.string()) .describe('Suggested follow-up questions'),});const VerificationResultSchema = z.object({ verified: z .boolean() .describe('Whether the report seems coherent and plausible'), issues: z .string() .describe('If not verified, describe the main issues'),});
Add descriptions to schema fields to guide the model:
const taskSchema = z.object({ title: z .string() .min(5) .max(100) .describe('A clear, concise task title'), description: z .string() .describe('Detailed description of what needs to be done'), priority: z .enum(['low', 'medium', 'high', 'urgent']) .describe('Task priority level based on importance and deadline'), estimatedHours: z .number() .positive() .describe('Estimated hours to complete the task'), tags: z .array(z.string()) .describe('Relevant tags for categorization (e.g., "bug", "feature", "docs")'),});