Skip to content

Commit 732c619

Browse files
committed
add 1s delay to simulate slow response
1 parent cb126fd commit 732c619

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

packages/demo-agents/src/slow-tool-call-streaming.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
AbstractAgent,
3-
RunAgentInput,
4-
EventType,
5-
BaseEvent,
6-
ToolCallResultEvent,
7-
} from "@ag-ui/client";
1+
import { AbstractAgent, RunAgentInput, EventType, BaseEvent, ToolCallResultEvent } from "@ag-ui/client";
82
import { Observable } from "rxjs";
93

104
export class SlowToolCallStreamingAgent extends AbstractAgent {
@@ -28,6 +22,7 @@ export class SlowToolCallStreamingAgent extends AbstractAgent {
2822
let cancelled = false;
2923

3024
const runAsync = async () => {
25+
await this.sleep(1000);
3126
try {
3227
const messageId = Date.now().toString();
3328
const toolCallId = `call_${Date.now()}`;
@@ -40,8 +35,7 @@ export class SlowToolCallStreamingAgent extends AbstractAgent {
4035
} as BaseEvent);
4136

4237
// Stream the initial text message
43-
const textMessage =
44-
"I'll check the weather for you. Let me fetch that information.";
38+
const textMessage = "I'll check the weather for you. Let me fetch that information ok?.";
4539
const chunks = textMessage.split(" ");
4640

4741
for (let i = 0; i < chunks.length; i++) {
@@ -115,10 +109,7 @@ export class SlowToolCallStreamingAgent extends AbstractAgent {
115109
if (!cancelled) {
116110
observer.next({
117111
type: EventType.RUN_ERROR,
118-
message:
119-
error instanceof Error
120-
? error.message
121-
: "Unknown error occurred",
112+
message: error instanceof Error ? error.message : "Unknown error occurred",
122113
} as BaseEvent);
123114
observer.error(error);
124115
}

0 commit comments

Comments
 (0)