11import { google } from "@ai-sdk/google" ;
22import { z } from "zod" ;
33import {
4- AIPexAgent ,
4+ AIPex ,
55 aisdk ,
66 ConversationCompressor ,
77 ConversationManager ,
@@ -23,13 +23,13 @@ async function main() {
2323 console . log ( "User: What is 15 * 234?" ) ;
2424 console . log ( "Assistant: " ) ;
2525
26- const simpleAgent = AIPexAgent . create ( {
26+ const simpleAgent = AIPex . create ( {
2727 instructions : "You are a helpful assistant that can perform calculations." ,
2828 model,
2929 tools : [ calculatorTool ] ,
3030 } ) ;
3131
32- for await ( const event of simpleAgent . executeStream ( "What is 15 * 234?" ) ) {
32+ for await ( const event of simpleAgent . chat ( "What is 15 * 234?" ) ) {
3333 if ( event . type === "content_delta" ) {
3434 process . stdout . write ( event . delta ) ;
3535 } else if ( event . type === "tool_call_complete" ) {
@@ -47,7 +47,7 @@ async function main() {
4747 const storage = new SessionStorage ( new InMemoryStorage < SerializedSession > ( ) ) ;
4848 const manager = new ConversationManager ( storage ) ;
4949
50- const agent = AIPexAgent . create ( {
50+ const agent = AIPex . create ( {
5151 instructions : "You are a helpful assistant with memory." ,
5252 model,
5353 tools : [ calculatorTool , httpFetchTool ] ,
@@ -59,7 +59,7 @@ async function main() {
5959 console . log ( "User: My name is Alice" ) ;
6060 console . log ( "Assistant: " ) ;
6161
62- for await ( const event of agent . executeStream ( "My name is Alice" ) ) {
62+ for await ( const event of agent . chat ( "My name is Alice" ) ) {
6363 if ( event . type === "session_created" ) {
6464 sessionId = event . sessionId ;
6565 console . log ( `[Session ${ sessionId } created]` ) ;
@@ -73,10 +73,7 @@ async function main() {
7373 console . log ( "\n\nUser: What is my name?" ) ;
7474 console . log ( "Assistant: " ) ;
7575
76- for await ( const event of agent . continueConversation (
77- sessionId ,
78- "What is my name?" ,
79- ) ) {
76+ for await ( const event of agent . chat ( "What is my name?" , { sessionId } ) ) {
8077 if ( event . type === "content_delta" ) {
8178 process . stdout . write ( event . delta ) ;
8279 }
@@ -106,7 +103,7 @@ async function main() {
106103 } ,
107104 } ) ;
108105
109- const weatherAgent = AIPexAgent . create ( {
106+ const weatherAgent = AIPex . create ( {
110107 instructions : "You are a weather assistant." ,
111108 model,
112109 tools : [ weatherTool ] ,
@@ -115,9 +112,7 @@ async function main() {
115112 console . log ( "User: What's the weather in Tokyo?" ) ;
116113 console . log ( "Assistant: " ) ;
117114
118- for await ( const event of weatherAgent . executeStream (
119- "What's the weather in Tokyo?" ,
120- ) ) {
115+ for await ( const event of weatherAgent . chat ( "What's the weather in Tokyo?" ) ) {
121116 if ( event . type === "content_delta" ) {
122117 process . stdout . write ( event . delta ) ;
123118 } else if ( event . type === "tool_call_complete" ) {
@@ -140,7 +135,7 @@ async function main() {
140135 compressor,
141136 } ) ;
142137
143- const compressAgent = AIPexAgent . create ( {
138+ const compressAgent = AIPex . create ( {
144139 instructions : "You are a helpful assistant." ,
145140 model,
146141 conversationManager : compressManager ,
@@ -159,9 +154,11 @@ async function main() {
159154 console . log ( `User: ${ msg } ` ) ;
160155 console . log ( "Assistant: " ) ;
161156
162- for await ( const event of compressSessionId
163- ? compressAgent . continueConversation ( compressSessionId , msg )
164- : compressAgent . executeStream ( msg ) ) {
157+ const stream = compressAgent . chat (
158+ msg ,
159+ compressSessionId ? { sessionId : compressSessionId } : undefined ,
160+ ) ;
161+ for await ( const event of stream ) {
165162 if ( event . type === "session_created" ) {
166163 compressSessionId = event . sessionId ;
167164 }
0 commit comments