Skip to content

Commit 0ea0655

Browse files
committed
chore(core): drop deprecated agent APIs
1 parent 6b9817c commit 0ea0655

File tree

9 files changed

+58
-173
lines changed

9 files changed

+58
-173
lines changed

packages/core/examples/basic-example.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { google } from "@ai-sdk/google";
22
import { z } from "zod";
33
import {
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
}

packages/core/examples/fork-example.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { openai } from "@ai-sdk/openai";
22
import {
3-
AIPexAgent,
3+
AIPex,
44
aisdk,
55
ConversationManager,
66
InMemoryStorage,
@@ -14,7 +14,7 @@ async function main() {
1414
const storage = new SessionStorage(new InMemoryStorage<SerializedSession>());
1515
const manager = new ConversationManager(storage);
1616

17-
const agent = AIPexAgent.create({
17+
const agent = AIPex.create({
1818
instructions: "You are a helpful assistant that remembers conversations.",
1919
model: aisdk(openai("gpt-4o")),
2020
conversationManager: manager,
@@ -28,7 +28,7 @@ async function main() {
2828
console.log("User: My favorite color is blue");
2929
console.log("Assistant: ");
3030

31-
for await (const event of agent.executeStream("My favorite color is blue")) {
31+
for await (const event of agent.chat("My favorite color is blue")) {
3232
if (event.type === "session_created") {
3333
mainSessionId = event.sessionId;
3434
console.log(`[Session ${mainSessionId} created]`);
@@ -46,10 +46,9 @@ async function main() {
4646
console.log("\n\nUser: My favorite food is sushi");
4747
console.log("Assistant: ");
4848

49-
for await (const event of agent.continueConversation(
50-
mainSessionId,
51-
"My favorite food is sushi",
52-
)) {
49+
for await (const event of agent.chat("My favorite food is sushi", {
50+
sessionId: mainSessionId,
51+
})) {
5352
if (event.type === "content_delta") {
5453
process.stdout.write(event.delta);
5554
}
@@ -58,10 +57,9 @@ async function main() {
5857
console.log("\n\nUser: I like playing tennis");
5958
console.log("Assistant: ");
6059

61-
for await (const event of agent.continueConversation(
62-
mainSessionId,
63-
"I like playing tennis",
64-
)) {
60+
for await (const event of agent.chat("I like playing tennis", {
61+
sessionId: mainSessionId,
62+
})) {
6563
if (event.type === "content_delta") {
6664
process.stdout.write(event.delta);
6765
}
@@ -77,10 +75,9 @@ async function main() {
7775
console.log("User: What do I like?");
7876
console.log("Assistant: ");
7977

80-
for await (const event of agent.continueConversation(
81-
mainSessionId,
82-
"What do I like?",
83-
)) {
78+
for await (const event of agent.chat("What do I like?", {
79+
sessionId: mainSessionId,
80+
})) {
8481
if (event.type === "content_delta") {
8582
process.stdout.write(event.delta);
8683
}
@@ -92,10 +89,9 @@ async function main() {
9289
console.log("User: My favorite food is pizza (different answer!)");
9390
console.log("Assistant: ");
9491

95-
for await (const event of agent.continueConversation(
96-
forkedSession.id,
97-
"My favorite food is pizza",
98-
)) {
92+
for await (const event of agent.chat("My favorite food is pizza", {
93+
sessionId: forkedSession.id,
94+
})) {
9995
if (event.type === "content_delta") {
10096
process.stdout.write(event.delta);
10197
}
@@ -104,10 +100,9 @@ async function main() {
104100
console.log("\n\nUser (in fork): What do I like?");
105101
console.log("Assistant: ");
106102

107-
for await (const event of agent.continueConversation(
108-
forkedSession.id,
109-
"What do I like?",
110-
)) {
103+
for await (const event of agent.chat("What do I like?", {
104+
sessionId: forkedSession.id,
105+
})) {
111106
if (event.type === "content_delta") {
112107
process.stdout.write(event.delta);
113108
}

packages/core/examples/metrics-example.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { openai } from "@ai-sdk/openai";
22
import {
3-
AIPexAgent,
3+
AIPex,
44
aisdk,
55
ConversationManager,
66
InMemoryStorage,
@@ -12,7 +12,7 @@ async function demonstrateMetrics() {
1212
const storage = new SessionStorage(new InMemoryStorage<SerializedSession>());
1313
const manager = new ConversationManager(storage);
1414

15-
const agent = AIPexAgent.create({
15+
const agent = AIPex.create({
1616
name: "MetricsDemo",
1717
instructions: "You are a helpful assistant that demonstrates metrics.",
1818
model: aisdk(openai("gpt-4o")),
@@ -22,7 +22,7 @@ async function demonstrateMetrics() {
2222

2323
console.log("Starting agent execution...\n");
2424

25-
for await (const event of agent.executeStream(
25+
for await (const event of agent.chat(
2626
"Hello! Can you help me understand how metrics work?",
2727
)) {
2828
switch (event.type) {

packages/core/src/agent/aipex.test.ts

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -259,82 +259,6 @@ describe("AIPex", () => {
259259
});
260260
});
261261

262-
describe("deprecated methods", () => {
263-
it("executeStream should work as alias for chat", async () => {
264-
vi.mocked(run).mockResolvedValue(
265-
createMockRunResult({
266-
finalOutput: "Hello!",
267-
streamEvents: [
268-
{
269-
type: "raw_model_stream_event",
270-
data: { type: "output_text_delta", delta: "Hello!" },
271-
},
272-
],
273-
}),
274-
);
275-
276-
const agent = AIPex.create({
277-
instructions: "Test",
278-
model: mockModel,
279-
});
280-
281-
const events: AgentEvent[] = [];
282-
for await (const event of agent.executeStream("Hi")) {
283-
events.push(event);
284-
}
285-
286-
expect(events[0]?.type).toBe("session_created");
287-
});
288-
289-
it("continueConversation should work for continuing sessions", async () => {
290-
vi.mocked(run).mockResolvedValue(
291-
createMockRunResult({
292-
finalOutput: "Response 1",
293-
streamEvents: [
294-
{
295-
type: "raw_model_stream_event",
296-
data: { type: "output_text_delta", delta: "Response 1" },
297-
},
298-
],
299-
}),
300-
);
301-
302-
const agent = AIPex.create({
303-
instructions: "Test",
304-
model: mockModel,
305-
});
306-
307-
let sessionId: string | undefined;
308-
for await (const event of agent.chat("First")) {
309-
if (event.type === "session_created") {
310-
sessionId = event.sessionId;
311-
}
312-
}
313-
314-
vi.mocked(run).mockResolvedValue(
315-
createMockRunResult({
316-
finalOutput: "Response 2",
317-
streamEvents: [
318-
{
319-
type: "raw_model_stream_event",
320-
data: { type: "output_text_delta", delta: "Response 2" },
321-
},
322-
],
323-
}),
324-
);
325-
326-
const events: AgentEvent[] = [];
327-
for await (const event of agent.continueConversation(
328-
sessionId!,
329-
"Second",
330-
)) {
331-
events.push(event);
332-
}
333-
334-
expect(events[0]?.type).toBe("session_resumed");
335-
});
336-
});
337-
338262
describe("create", () => {
339263
it("should use default values when options not provided", () => {
340264
const agent = AIPex.create({

packages/core/src/agent/aipex.ts

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,26 @@ export class AIPex {
258258

259259
// If sessionId is provided, continue existing conversation
260260
if (chatOptions?.sessionId) {
261-
yield* this.continueConversation(chatOptions.sessionId, finalInput);
261+
if (!this.conversationManager) {
262+
throw new Error(
263+
"ConversationManager is required for continuing conversations",
264+
);
265+
}
266+
267+
const session = await this.conversationManager.getSession(
268+
chatOptions.sessionId,
269+
);
270+
if (!session) {
271+
throw new Error(`Session ${chatOptions.sessionId} not found`);
272+
}
273+
274+
yield {
275+
type: "session_resumed",
276+
sessionId: chatOptions.sessionId,
277+
itemCount: session.getItemCount(),
278+
};
279+
280+
yield* this.runExecution(finalInput, session);
262281
return;
263282
}
264283

@@ -273,40 +292,6 @@ export class AIPex {
273292
yield* this.runExecution(finalInput, session);
274293
}
275294

276-
/**
277-
* @deprecated Use chat() instead
278-
*/
279-
async *executeStream(input: string): AsyncGenerator<AgentEvent> {
280-
yield* this.chat(input);
281-
}
282-
283-
/**
284-
* @deprecated Use chat(input, { sessionId }) instead
285-
*/
286-
async *continueConversation(
287-
sessionId: string,
288-
input: string,
289-
): AsyncGenerator<AgentEvent> {
290-
if (!this.conversationManager) {
291-
throw new Error(
292-
"ConversationManager is required for continuing conversations",
293-
);
294-
}
295-
296-
const session = await this.conversationManager.getSession(sessionId);
297-
if (!session) {
298-
throw new Error(`Session ${sessionId} not found`);
299-
}
300-
301-
yield {
302-
type: "session_resumed",
303-
sessionId,
304-
itemCount: session.getItemCount(),
305-
};
306-
307-
yield* this.runExecution(input, session);
308-
}
309-
310295
getConversationManager(): ConversationManager | undefined {
311296
return this.conversationManager;
312297
}

packages/core/src/agent/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
export type {
22
AgentEvent,
33
AgentMetrics,
4-
AIPexAgentOptions,
54
AIPexOptions,
65
ChatOptions,
76
FunctionTool,
87
OpenAIAgent,
98
} from "../types.js";
10-
/**
11-
* @deprecated Use AIPex instead
12-
*/
13-
export { AIPex, AIPex as AIPexAgent } from "./aipex.js";
9+
export { AIPex } from "./aipex.js";

packages/core/src/config/ai-providers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const AI_PROVIDERS = {
4646
name: "Google",
4747
icon: "🔍",
4848
models: [
49-
"gemini-2.0-flash-exp",
49+
"gemini-2.5-flash-exp",
5050
"gemini-1.5-pro",
5151
"gemini-1.5-flash",
5252
] as const,

0 commit comments

Comments
 (0)