1010 * pnpm -C packages/core run real-api:smoke
1111 */
1212
13- import { CascadeAgent } from '../src/index.ts' ;
13+ import { CascadeAgent , ToolConfig , ToolExecutor } from '../src/index.ts' ;
1414import type { Tool } from '../src/types.ts' ;
1515
1616type Env = Record < string , string | undefined > ;
@@ -44,6 +44,24 @@ async function main(): Promise<void> {
4444 const anthropicKey = env . ANTHROPIC_API_KEY ;
4545
4646 if ( openaiKey ) {
47+ const toolExecutor = new ToolExecutor ( [
48+ new ToolConfig ( {
49+ name : 'get_weather' ,
50+ description : 'Get the weather for a location.' ,
51+ parameters : {
52+ type : 'object' ,
53+ properties : {
54+ location : { type : 'string' } ,
55+ } ,
56+ required : [ 'location' ] ,
57+ } ,
58+ function : async ( { location } : { location ?: string } ) => ( {
59+ location : location || 'unknown' ,
60+ forecast : 'sunny' ,
61+ } ) ,
62+ } ) ,
63+ ] ) ;
64+
4765 const agent = new CascadeAgent ( {
4866 models : [
4967 { name : 'gpt-4o-mini' , provider : 'openai' , cost : 0.00015 , apiKey : openaiKey } ,
@@ -61,11 +79,7 @@ async function main(): Promise<void> {
6179 tools : [ getWeatherTool ] ,
6280 forceDirect : true ,
6381 maxSteps : 3 ,
64- toolExecutor : async ( call ) => {
65- const name = call . function ?. name ?? call . name ;
66- if ( name !== 'get_weather' ) return { ok : false , error : 'unknown_tool' } ;
67- return { location : 'Paris' , forecast : 'sunny' } ;
68- } ,
82+ toolExecutor,
6983 } ) ;
7084 if ( ! r2 . content || ! / s u n n y / i. test ( r2 . content ) ) {
7185 throw new Error ( `OpenAI tool-loop smoke failed: content=${ JSON . stringify ( r2 . content ) } ` ) ;
0 commit comments