88 type WSMessage ,
99 routeAgentRequest
1010} from "agents" ;
11- import { generateObject , generateText } from "ai" ;
11+ import { generateObject , generateText , type LanguageModel } from "ai" ;
1212import { z } from "zod" ;
1313
1414type Env = {
@@ -129,7 +129,7 @@ export const Sequential = createAgent<{ input: string }, { copy: string }>(
129129 console . log ( "Sequential" , props ) ;
130130 // This agent uses a prompt chaining workflow, ideal for tasks that can be decomposed into fixed subtasks.
131131 // It trades off latency for higher accuracy by making each LLM call an easier task.
132- const model = ctx . openai ( "gpt-4o" ) ;
132+ const model = ctx . openai ( "gpt-4o" ) as unknown as LanguageModel ;
133133
134134 // First step: Generate marketing copy
135135 const { text : copy } = await generateText ( {
@@ -191,7 +191,7 @@ export const Routing = createAgent<{ query: string }, { response: string }>(
191191 ) => {
192192 // This agent uses a routing workflow, which classifies input and directs it to specialized follow-up tasks.
193193 // It is effective for complex tasks with distinct categories that are better handled separately.
194- const model = ctx . openai ( "gpt-4o" ) ;
194+ const model = ctx . openai ( "gpt-4o" ) as unknown as LanguageModel ;
195195
196196 // First step: Classify the query type
197197 const { object : classification } = await generateObject ( {
@@ -205,7 +205,7 @@ export const Routing = createAgent<{ query: string }, { response: string }>(
205205 3. Brief reasoning for classification` ,
206206 schema : z . object ( {
207207 complexity : z . enum ( [ "simple" , "complex" ] ) ,
208- reasoning : z . string ( ) ,
208+ reasoningText : z . string ( ) ,
209209 type : z . enum ( [ "general" , "refund" , "technical" ] )
210210 } )
211211 } ) ;
@@ -215,8 +215,8 @@ export const Routing = createAgent<{ query: string }, { response: string }>(
215215 const { text : response } = await generateText ( {
216216 model :
217217 classification . complexity === "simple"
218- ? ctx . openai ( "gpt-4o-mini" )
219- : ctx . openai ( "o1-mini" ) ,
218+ ? ( ctx . openai ( "gpt-4o-mini" ) as unknown as LanguageModel )
219+ : ( ctx . openai ( "o1-mini" ) as unknown as LanguageModel ) ,
220220 prompt : props . query ,
221221 system : {
222222 general :
@@ -244,7 +244,7 @@ export const Parallel = createAgent<
244244 ) => {
245245 // This agent uses a parallelization workflow, effective for tasks that can be divided into independent subtasks.
246246 // It allows for speed and multiple perspectives, improving confidence in results.
247- const model = ctx . openai ( "gpt-4o" ) ;
247+ const model = ctx . openai ( "gpt-4o" ) as unknown as LanguageModel ;
248248
249249 // Run parallel reviews
250250 const [ securityReview , performanceReview , maintainabilityReview ] =
@@ -336,7 +336,7 @@ export const Orchestrator = createAgent<
336336 // This agent uses an orchestrator-workers workflow, suitable for complex tasks where subtasks aren't pre-defined.
337337 // It dynamically breaks down tasks and delegates them to worker LLMs, synthesizing their results.
338338 const { object : implementationPlan } = await generateObject ( {
339- model : ctx . openai ( "o1" ) ,
339+ model : ctx . openai ( "o1" ) as unknown as LanguageModel ,
340340 prompt : `Analyze this feature request and create an implementation plan:
341341 ${ props . featureRequest } ` ,
342342 schema : z . object ( {
@@ -367,7 +367,7 @@ export const Orchestrator = createAgent<
367367 } [ file . changeType ] ;
368368
369369 const { object : change } = await generateObject ( {
370- model : ctx . openai ( "gpt-4o" ) ,
370+ model : ctx . openai ( "gpt-4o" ) as unknown as LanguageModel ,
371371 prompt : `Implement the changes for ${ file . filePath } to support:
372372 ${ file . purpose }
373373
@@ -402,15 +402,15 @@ export const Evaluator = createAgent(
402402 props : { text : string ; targetLanguage : string } ,
403403 ctx : { toast : ( message : string ) => void ; openai : OpenAIProvider }
404404 ) => {
405- const model = ctx . openai ( "gpt-4o" ) ;
405+ const model = ctx . openai ( "gpt-4o" ) as unknown as LanguageModel ;
406406
407407 let currentTranslation = "" ;
408408 let iterations = 0 ;
409409 const MAX_ITERATIONS = 1 ;
410410
411411 // Initial translation
412412 const { text : translation } = await generateText ( {
413- model : ctx . openai ( "gpt-4o-mini" ) , // use small model for first attempt
413+ model : ctx . openai ( "gpt-4o-mini" ) as unknown as LanguageModel , // use small model for first attempt
414414 prompt : `Translate this text to ${ props . targetLanguage } , preserving tone and cultural nuances:
415415 ${ props . text } ` ,
416416 system : "You are an expert literary translator."
@@ -460,7 +460,7 @@ export const Evaluator = createAgent(
460460
461461 // Generate improved translation based on feedback
462462 const { text : improvedTranslation } = await generateText ( {
463- model : ctx . openai ( "gpt-4o" ) , // use a larger model
463+ model : ctx . openai ( "gpt-4o" ) as unknown as LanguageModel , // use a larger model
464464 prompt : `Improve this translation based on the following feedback:
465465 ${ evaluation . specificIssues . join ( "\n" ) }
466466 ${ evaluation . improvementSuggestions . join ( "\n" ) }
0 commit comments