@agentscope-ai/agentscope 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/LICENSE +202 -0
  2. package/dist/agent/index.d.mts +10 -10
  3. package/dist/agent/index.d.ts +10 -10
  4. package/dist/agent/index.js +104 -93
  5. package/dist/agent/index.js.map +1 -1
  6. package/dist/agent/index.mjs +104 -93
  7. package/dist/agent/index.mjs.map +1 -1
  8. package/dist/{base-BOx3UzOl.d.mts → base-1YVBgB4n.d.mts} +2 -2
  9. package/dist/{base-DYlBMCy_.d.mts → base-B_MQMHWr.d.mts} +3 -3
  10. package/dist/{base-Cwi4bjze.d.ts → base-BherSLRs.d.ts} +3 -3
  11. package/dist/{base-NX-knWOv.d.ts → base-CY4DMBH1.d.ts} +1 -1
  12. package/dist/{base-BoIps2RL.d.ts → base-ChWjyzPL.d.ts} +2 -2
  13. package/dist/{base-C7jwyH4Z.d.mts → base-ClilytRZ.d.mts} +1 -1
  14. package/dist/{block-VsnHrllL.d.mts → block-B72uPF1H.d.mts} +7 -5
  15. package/dist/{block-VsnHrllL.d.ts → block-B72uPF1H.d.ts} +7 -5
  16. package/dist/event/index.d.mts +105 -89
  17. package/dist/event/index.d.ts +105 -89
  18. package/dist/event/index.js +8 -8
  19. package/dist/event/index.js.map +1 -1
  20. package/dist/event/index.mjs +8 -8
  21. package/dist/event/index.mjs.map +1 -1
  22. package/dist/formatter/index.d.mts +4 -3
  23. package/dist/formatter/index.d.ts +4 -3
  24. package/dist/formatter/index.js +17 -17
  25. package/dist/formatter/index.js.map +1 -1
  26. package/dist/formatter/index.mjs +17 -17
  27. package/dist/formatter/index.mjs.map +1 -1
  28. package/dist/{index-BcatlwXQ.d.ts → index-BNfyKbQN.d.ts} +1 -1
  29. package/dist/{index-BTJDlKvQ.d.mts → index-UQCwdfet.d.mts} +1 -1
  30. package/dist/mcp/index.d.mts +2 -2
  31. package/dist/mcp/index.d.ts +2 -2
  32. package/dist/mcp/index.js +1 -1
  33. package/dist/mcp/index.js.map +1 -1
  34. package/dist/mcp/index.mjs +1 -1
  35. package/dist/mcp/index.mjs.map +1 -1
  36. package/dist/message/index.d.mts +3 -2
  37. package/dist/message/index.d.ts +3 -2
  38. package/dist/message/index.js +204 -5
  39. package/dist/message/index.js.map +1 -1
  40. package/dist/message/index.mjs +200 -5
  41. package/dist/message/index.mjs.map +1 -1
  42. package/dist/message-CPZd0NIc.d.ts +133 -0
  43. package/dist/message-DgpfAaHK.d.mts +133 -0
  44. package/dist/model/index.d.mts +6 -5
  45. package/dist/model/index.d.ts +6 -5
  46. package/dist/model/index.js +39 -28
  47. package/dist/model/index.js.map +1 -1
  48. package/dist/model/index.mjs +39 -28
  49. package/dist/model/index.mjs.map +1 -1
  50. package/dist/storage/index.d.mts +4 -3
  51. package/dist/storage/index.d.ts +4 -3
  52. package/dist/storage/index.js +4 -4
  53. package/dist/storage/index.js.map +1 -1
  54. package/dist/storage/index.mjs +4 -4
  55. package/dist/storage/index.mjs.map +1 -1
  56. package/dist/tool/index.d.mts +4 -4
  57. package/dist/tool/index.d.ts +4 -4
  58. package/dist/{toolkit-CEpulFi0.d.ts → toolkit-DeOlul5Y.d.ts} +2 -2
  59. package/dist/{toolkit-CGEZSZPa.d.mts → toolkit-jwe7NmVJ.d.mts} +2 -2
  60. package/package.json +87 -87
  61. package/src/agent/agent.test.ts +104 -71
  62. package/src/agent/agent.ts +112 -104
  63. package/src/agent/test-compression.ts +1 -1
  64. package/src/event/index.ts +96 -98
  65. package/src/formatter/base.ts +3 -3
  66. package/src/formatter/dashscope-chat-formatter.test.ts +11 -8
  67. package/src/formatter/dashscope-chat-formatter.ts +3 -3
  68. package/src/formatter/openai-chat-formatter.test.ts +13 -5
  69. package/src/formatter/openai-chat-formatter.ts +6 -6
  70. package/src/mcp/base.ts +1 -1
  71. package/src/mcp/http.test.ts +2 -0
  72. package/src/mcp/stdio.test.ts +1 -0
  73. package/src/message/append-event.test.ts +783 -0
  74. package/src/message/block.ts +8 -4
  75. package/src/message/index.ts +12 -1
  76. package/src/message/message.test.ts +3 -1
  77. package/src/message/message.ts +310 -47
  78. package/src/model/dashscope-model.test.ts +4 -0
  79. package/src/model/dashscope-model.ts +3 -0
  80. package/src/model/deepseek-model.test.ts +2 -0
  81. package/src/model/deepseek-model.ts +3 -0
  82. package/src/model/ollama-model.test.ts +1 -0
  83. package/src/model/ollama-model.ts +2 -0
  84. package/src/model/openai-model.ts +3 -0
  85. package/src/permission/index.ts +13 -0
  86. package/src/storage/file-system.test.ts +4 -3
  87. package/src/storage/file-system.ts +4 -4
  88. package/src/tool/toolkit.test.ts +12 -0
  89. package/dist/message-CkN21KaY.d.mts +0 -99
  90. package/dist/message-CzLeTlua.d.ts +0 -99
@@ -76,12 +76,14 @@ describe('Human-in-the-loop', () => {
76
76
  id: '1',
77
77
  name: 'Bash',
78
78
  input: `{"command": "echo Hello"}`,
79
+ state: 'pending',
79
80
  },
80
81
  {
81
82
  type: 'tool_call',
82
83
  id: '2',
83
84
  name: 'Bash',
84
85
  input: `{"command": "echo World"}`,
86
+ state: 'pending',
85
87
  },
86
88
  ];
87
89
 
@@ -93,26 +95,26 @@ describe('Human-in-the-loop', () => {
93
95
 
94
96
  expect(lastEvent).toMatchObject({
95
97
  type: EventType.REQUIRE_USER_CONFIRM,
96
- toolCalls: [
98
+ tool_calls: [
97
99
  {
98
100
  type: 'tool_call',
99
101
  id: '1',
100
102
  name: 'Bash',
101
103
  input: '{"command": "echo Hello"}',
102
- awaitUserConfirmation: true,
104
+ state: 'asking',
103
105
  },
104
106
  {
105
107
  type: 'tool_call',
106
108
  id: '2',
107
109
  name: 'Bash',
108
110
  input: '{"command": "echo World"}',
109
- awaitUserConfirmation: true,
111
+ state: 'asking',
110
112
  },
111
113
  ],
112
114
  });
113
115
 
114
116
  expect(await agent.toJSON()).toMatchObject({
115
- replyId: expect.any(String),
117
+ reply_id: expect.any(String),
116
118
  confirmedToolCallIds: [],
117
119
  curIter: 0,
118
120
  });
@@ -126,21 +128,21 @@ describe('Human-in-the-loop', () => {
126
128
  input: '{"command": "echo Hello"}',
127
129
  name: 'Bash',
128
130
  type: 'tool_call',
129
- awaitUserConfirmation: true,
131
+ state: 'asking',
130
132
  },
131
133
  {
132
134
  id: '2',
133
135
  input: '{"command": "echo World"}',
134
136
  name: 'Bash',
135
137
  type: 'tool_call',
136
- awaitUserConfirmation: true,
138
+ state: 'asking',
137
139
  },
138
140
  ],
139
141
  id: expect.any(String),
140
142
  metadata: {},
141
143
  name: 'Friday',
142
144
  role: 'assistant',
143
- timestamp: expect.any(String),
145
+ created_at: expect.any(String),
144
146
  },
145
147
  ]);
146
148
 
@@ -148,17 +150,18 @@ describe('Human-in-the-loop', () => {
148
150
  for await (const event of agent.replyStream({
149
151
  event: {
150
152
  id: 'xxx',
151
- createdAt: new Date().toISOString(),
153
+ created_at: new Date().toISOString(),
152
154
  type: EventType.USER_CONFIRM_RESULT,
153
- replyId: agent.replyId,
154
- confirmResults: [
155
+ reply_id: agent.replyId,
156
+ confirm_results: [
155
157
  {
156
158
  confirmed: true,
157
- toolCall: {
159
+ tool_call: {
158
160
  type: 'tool_call',
159
161
  id: '1',
160
162
  name: 'Bash',
161
163
  input: '{"command": "echo Hello"}',
164
+ state: 'pending',
162
165
  },
163
166
  },
164
167
  ],
@@ -170,13 +173,14 @@ describe('Human-in-the-loop', () => {
170
173
  // Verify the agent still yields user confirmation for the second tool call
171
174
  expect(lastEvent).toMatchObject({
172
175
  type: EventType.REQUIRE_USER_CONFIRM,
173
- replyId: expect.any(String),
174
- toolCalls: [
176
+ reply_id: expect.any(String),
177
+ tool_calls: [
175
178
  {
176
179
  type: 'tool_call',
177
180
  id: '2',
178
181
  name: 'Bash',
179
182
  input: '{"command": "echo World"}',
183
+ state: 'asking',
180
184
  },
181
185
  ],
182
186
  });
@@ -189,13 +193,14 @@ describe('Human-in-the-loop', () => {
189
193
  input: '{"command": "echo Hello"}',
190
194
  name: 'Bash',
191
195
  type: 'tool_call',
196
+ state: 'allowed',
192
197
  },
193
198
  {
194
199
  id: '2',
195
200
  input: '{"command": "echo World"}',
196
201
  name: 'Bash',
197
202
  type: 'tool_call',
198
- awaitUserConfirmation: true,
203
+ state: 'asking',
199
204
  },
200
205
  {
201
206
  id: '1',
@@ -219,17 +224,18 @@ describe('Human-in-the-loop', () => {
219
224
  const res = agent.replyStream({
220
225
  event: {
221
226
  id: 'xxx',
222
- createdAt: new Date().toISOString(),
227
+ created_at: new Date().toISOString(),
223
228
  type: EventType.USER_CONFIRM_RESULT,
224
- replyId: agent.replyId,
225
- confirmResults: [
229
+ reply_id: agent.replyId,
230
+ confirm_results: [
226
231
  {
227
232
  confirmed: false,
228
- toolCall: {
233
+ tool_call: {
229
234
  type: 'tool_call',
230
235
  id: '2',
231
236
  name: 'Bash',
232
237
  input: '{"command": "echo World"}',
238
+ state: 'pending',
233
239
  },
234
240
  },
235
241
  ],
@@ -249,9 +255,9 @@ describe('Human-in-the-loop', () => {
249
255
  // Verify the lastEvent
250
256
  expect(lastEvent).toMatchObject({
251
257
  id: expect.any(String),
252
- type: EventType.RUN_FINISHED,
253
- createdAt: expect.any(String),
254
- replyId: agent.replyId,
258
+ type: EventType.REPLY_END,
259
+ created_at: expect.any(String),
260
+ reply_id: agent.replyId,
255
261
  });
256
262
 
257
263
  // Verify the final agent reply msg
@@ -267,7 +273,7 @@ describe('Human-in-the-loop', () => {
267
273
  metadata: {},
268
274
  name: 'Friday',
269
275
  role: 'assistant',
270
- timestamp: expect.any(String),
276
+ created_at: expect.any(String),
271
277
  });
272
278
  });
273
279
 
@@ -312,12 +318,14 @@ describe('Human-in-the-loop', () => {
312
318
  id: '1',
313
319
  name: 'ExternalTool1',
314
320
  input: `{"query": "test query"}`,
321
+ state: 'pending',
315
322
  },
316
323
  {
317
324
  type: 'tool_call',
318
325
  id: '2',
319
326
  name: 'ExternalTool2',
320
327
  input: `{"data": "test data"}`,
328
+ state: 'pending',
321
329
  },
322
330
  ];
323
331
 
@@ -330,25 +338,27 @@ describe('Human-in-the-loop', () => {
330
338
  // Verify the agent emits REQUIRE_EXTERNAL_EXECUTION event
331
339
  expect(lastEvent).toMatchObject({
332
340
  type: EventType.REQUIRE_EXTERNAL_EXECUTION,
333
- toolCalls: [
341
+ tool_calls: [
334
342
  {
335
343
  type: 'tool_call',
336
344
  id: '1',
337
345
  name: 'ExternalTool1',
338
346
  input: '{"query": "test query"}',
347
+ state: 'pending',
339
348
  },
340
349
  {
341
350
  type: 'tool_call',
342
351
  id: '2',
343
352
  name: 'ExternalTool2',
344
353
  input: '{"data": "test data"}',
354
+ state: 'pending',
345
355
  },
346
356
  ],
347
357
  });
348
358
 
349
359
  // Verify agent state
350
360
  expect(await agent.toJSON()).toMatchObject({
351
- replyId: expect.any(String),
361
+ reply_id: expect.any(String),
352
362
  confirmedToolCallIds: [],
353
363
  curIter: 0,
354
364
  });
@@ -362,19 +372,22 @@ describe('Human-in-the-loop', () => {
362
372
  input: '{"query": "test query"}',
363
373
  name: 'ExternalTool1',
364
374
  type: 'tool_call',
375
+ state: 'pending',
365
376
  },
366
377
  {
367
378
  id: '2',
368
379
  input: '{"data": "test data"}',
369
380
  name: 'ExternalTool2',
370
381
  type: 'tool_call',
382
+ state: 'pending',
371
383
  },
372
384
  ],
373
385
  id: expect.any(String),
374
386
  metadata: {},
375
387
  name: 'Friday',
376
388
  role: 'assistant',
377
- timestamp: expect.any(String),
389
+ created_at: expect.any(String),
390
+ finished_at: undefined,
378
391
  },
379
392
  ]);
380
393
 
@@ -382,10 +395,10 @@ describe('Human-in-the-loop', () => {
382
395
  for await (const event of agent.replyStream({
383
396
  event: {
384
397
  id: 'xxx',
385
- createdAt: new Date().toISOString(),
398
+ created_at: new Date().toISOString(),
386
399
  type: EventType.EXTERNAL_EXECUTION_RESULT,
387
- replyId: agent.replyId,
388
- executionResults: [
400
+ reply_id: agent.replyId,
401
+ execution_results: [
389
402
  {
390
403
  type: 'tool_result',
391
404
  id: '1',
@@ -408,13 +421,14 @@ describe('Human-in-the-loop', () => {
408
421
  // Verify the agent still requires external execution for the second tool
409
422
  expect(lastEvent).toMatchObject({
410
423
  type: EventType.REQUIRE_EXTERNAL_EXECUTION,
411
- replyId: expect.any(String),
412
- toolCalls: [
424
+ reply_id: expect.any(String),
425
+ tool_calls: [
413
426
  {
414
427
  type: 'tool_call',
415
428
  id: '2',
416
429
  name: 'ExternalTool2',
417
430
  input: '{"data": "test data"}',
431
+ state: 'pending',
418
432
  },
419
433
  ],
420
434
  });
@@ -427,12 +441,14 @@ describe('Human-in-the-loop', () => {
427
441
  input: '{"query": "test query"}',
428
442
  name: 'ExternalTool1',
429
443
  type: 'tool_call',
444
+ state: 'pending',
430
445
  },
431
446
  {
432
447
  id: '2',
433
448
  input: '{"data": "test data"}',
434
449
  name: 'ExternalTool2',
435
450
  type: 'tool_call',
451
+ state: 'pending',
436
452
  },
437
453
  {
438
454
  id: '1',
@@ -456,10 +472,10 @@ describe('Human-in-the-loop', () => {
456
472
  const res = agent.replyStream({
457
473
  event: {
458
474
  id: 'xxx',
459
- createdAt: new Date().toISOString(),
475
+ created_at: new Date().toISOString(),
460
476
  type: EventType.EXTERNAL_EXECUTION_RESULT,
461
- replyId: agent.replyId,
462
- executionResults: [
477
+ reply_id: agent.replyId,
478
+ execution_results: [
463
479
  {
464
480
  type: 'tool_result',
465
481
  id: '2',
@@ -490,9 +506,9 @@ describe('Human-in-the-loop', () => {
490
506
  // Verify the lastEvent is RUN_FINISHED
491
507
  expect(lastEvent).toMatchObject({
492
508
  id: expect.any(String),
493
- type: EventType.RUN_FINISHED,
494
- createdAt: expect.any(String),
495
- replyId: agent.replyId,
509
+ type: EventType.REPLY_END,
510
+ created_at: expect.any(String),
511
+ reply_id: agent.replyId,
496
512
  });
497
513
 
498
514
  // Verify the final agent reply msg
@@ -508,7 +524,7 @@ describe('Human-in-the-loop', () => {
508
524
  metadata: {},
509
525
  name: 'Friday',
510
526
  role: 'assistant',
511
- timestamp: expect.any(String),
527
+ created_at: expect.any(String),
512
528
  });
513
529
  });
514
530
 
@@ -578,18 +594,21 @@ describe('Human-in-the-loop', () => {
578
594
  id: '1',
579
595
  name: 'ExternalTool',
580
596
  input: `{"query": "external query"}`,
597
+ state: 'pending',
581
598
  },
582
599
  {
583
600
  type: 'tool_call',
584
601
  id: '2',
585
602
  name: 'ConfirmTool',
586
603
  input: `{"action": "delete file"}`,
604
+ state: 'pending',
587
605
  },
588
606
  {
589
607
  type: 'tool_call',
590
608
  id: '3',
591
609
  name: 'NormalTool',
592
610
  input: `{"data": "normal data"}`,
611
+ state: 'pending',
593
612
  },
594
613
  ];
595
614
 
@@ -602,19 +621,20 @@ describe('Human-in-the-loop', () => {
602
621
  // Verify the agent emits REQUIRE_EXTERNAL_EXECUTION event for the first tool
603
622
  expect(lastEvent).toMatchObject({
604
623
  type: EventType.REQUIRE_EXTERNAL_EXECUTION,
605
- toolCalls: [
624
+ tool_calls: [
606
625
  {
607
626
  type: 'tool_call',
608
627
  id: '1',
609
628
  name: 'ExternalTool',
610
629
  input: '{"query": "external query"}',
630
+ state: 'pending',
611
631
  },
612
632
  ],
613
633
  });
614
634
 
615
635
  // Verify agent state
616
636
  expect(await agent.toJSON()).toMatchObject({
617
- replyId: expect.any(String),
637
+ reply_id: expect.any(String),
618
638
  confirmedToolCallIds: [],
619
639
  curIter: 0,
620
640
  });
@@ -623,10 +643,10 @@ describe('Human-in-the-loop', () => {
623
643
  for await (const event of agent.replyStream({
624
644
  event: {
625
645
  id: 'xxx',
626
- createdAt: new Date().toISOString(),
646
+ created_at: new Date().toISOString(),
627
647
  type: EventType.EXTERNAL_EXECUTION_RESULT,
628
- replyId: agent.replyId,
629
- executionResults: [
648
+ reply_id: agent.replyId,
649
+ execution_results: [
630
650
  {
631
651
  type: 'tool_result',
632
652
  id: '1',
@@ -649,21 +669,21 @@ describe('Human-in-the-loop', () => {
649
669
  // Verify the agent now requires user confirmation for the second tool
650
670
  expect(lastEvent).toMatchObject({
651
671
  type: EventType.REQUIRE_USER_CONFIRM,
652
- replyId: expect.any(String),
653
- toolCalls: [
672
+ reply_id: expect.any(String),
673
+ tool_calls: [
654
674
  {
655
675
  type: 'tool_call',
656
676
  id: '2',
657
677
  name: 'ConfirmTool',
658
678
  input: '{"action": "delete file"}',
659
- awaitUserConfirmation: true,
679
+ state: 'asking',
660
680
  },
661
681
  ],
662
682
  });
663
683
 
664
684
  // Verify agent state after external execution
665
685
  expect(await agent.toJSON()).toMatchObject({
666
- replyId: expect.any(String),
686
+ reply_id: expect.any(String),
667
687
  confirmedToolCallIds: [],
668
688
  curIter: 0,
669
689
  });
@@ -681,17 +701,18 @@ describe('Human-in-the-loop', () => {
681
701
  for await (const event of agent.replyStream({
682
702
  event: {
683
703
  id: 'xxx',
684
- createdAt: new Date().toISOString(),
704
+ created_at: new Date().toISOString(),
685
705
  type: EventType.USER_CONFIRM_RESULT,
686
- replyId: agent.replyId,
687
- confirmResults: [
706
+ reply_id: agent.replyId,
707
+ confirm_results: [
688
708
  {
689
709
  confirmed: true,
690
- toolCall: {
710
+ tool_call: {
691
711
  type: 'tool_call',
692
712
  id: '2',
693
713
  name: 'ConfirmTool',
694
714
  input: '{"action": "delete file"}',
715
+ state: 'pending',
695
716
  },
696
717
  },
697
718
  ],
@@ -703,9 +724,9 @@ describe('Human-in-the-loop', () => {
703
724
  // Verify the lastEvent is RUN_FINISHED
704
725
  expect(lastEvent).toMatchObject({
705
726
  id: expect.any(String),
706
- type: EventType.RUN_FINISHED,
707
- createdAt: expect.any(String),
708
- replyId: agent.replyId,
727
+ type: EventType.REPLY_END,
728
+ created_at: expect.any(String),
729
+ reply_id: agent.replyId,
709
730
  });
710
731
 
711
732
  // Verify the agent context includes all three tool calls, their results, and the final text
@@ -716,18 +737,21 @@ describe('Human-in-the-loop', () => {
716
737
  input: '{"query": "external query"}',
717
738
  name: 'ExternalTool',
718
739
  type: 'tool_call',
740
+ state: 'pending',
719
741
  },
720
742
  {
721
743
  id: '2',
722
744
  input: '{"action": "delete file"}',
723
745
  name: 'ConfirmTool',
724
746
  type: 'tool_call',
747
+ state: 'allowed',
725
748
  },
726
749
  {
727
750
  id: '3',
728
751
  input: '{"data": "normal data"}',
729
752
  name: 'NormalTool',
730
753
  type: 'tool_call',
754
+ state: 'pending',
731
755
  },
732
756
  {
733
757
  id: '1',
@@ -823,12 +847,14 @@ describe('Human-in-the-loop', () => {
823
847
  id: '1',
824
848
  name: 'ExternalAndConfirmTool',
825
849
  input: `{"command": "rm -rf /"}`,
850
+ state: 'pending',
826
851
  },
827
852
  {
828
853
  type: 'tool_call',
829
854
  id: '2',
830
855
  name: 'ConfirmOnlyTool',
831
856
  input: `{"action": "delete database"}`,
857
+ state: 'pending',
832
858
  },
833
859
  ];
834
860
 
@@ -841,27 +867,27 @@ describe('Human-in-the-loop', () => {
841
867
  // Verify the agent emits REQUIRE_USER_CONFIRM event for both tools
842
868
  expect(lastEvent).toMatchObject({
843
869
  type: EventType.REQUIRE_USER_CONFIRM,
844
- toolCalls: [
870
+ tool_calls: [
845
871
  {
846
872
  type: 'tool_call',
847
873
  id: '1',
848
874
  name: 'ExternalAndConfirmTool',
849
875
  input: '{"command": "rm -rf /"}',
850
- awaitUserConfirmation: true,
876
+ state: 'asking',
851
877
  },
852
878
  {
853
879
  type: 'tool_call',
854
880
  id: '2',
855
881
  name: 'ConfirmOnlyTool',
856
882
  input: '{"action": "delete database"}',
857
- awaitUserConfirmation: true,
883
+ state: 'asking',
858
884
  },
859
885
  ],
860
886
  });
861
887
 
862
888
  // Verify agent state
863
889
  expect(await agent.toJSON()).toMatchObject({
864
- replyId: expect.any(String),
890
+ reply_id: expect.any(String),
865
891
  confirmedToolCallIds: [],
866
892
  curIter: 0,
867
893
  });
@@ -870,26 +896,28 @@ describe('Human-in-the-loop', () => {
870
896
  for await (const event of agent.replyStream({
871
897
  event: {
872
898
  id: 'xxx',
873
- createdAt: new Date().toISOString(),
899
+ created_at: new Date().toISOString(),
874
900
  type: EventType.USER_CONFIRM_RESULT,
875
- replyId: agent.replyId,
876
- confirmResults: [
901
+ reply_id: agent.replyId,
902
+ confirm_results: [
877
903
  {
878
904
  confirmed: true,
879
- toolCall: {
905
+ tool_call: {
880
906
  type: 'tool_call',
881
907
  id: '1',
882
908
  name: 'ExternalAndConfirmTool',
883
909
  input: '{"command": "rm -rf /"}',
910
+ state: 'pending',
884
911
  },
885
912
  },
886
913
  {
887
914
  confirmed: true,
888
- toolCall: {
915
+ tool_call: {
889
916
  type: 'tool_call',
890
917
  id: '2',
891
918
  name: 'ConfirmOnlyTool',
892
919
  input: '{"action": "delete database"}',
920
+ state: 'pending',
893
921
  },
894
922
  },
895
923
  ],
@@ -901,20 +929,21 @@ describe('Human-in-the-loop', () => {
901
929
  // After user confirmation, the first tool requires external execution
902
930
  expect(lastEvent).toMatchObject({
903
931
  type: EventType.REQUIRE_EXTERNAL_EXECUTION,
904
- replyId: expect.any(String),
905
- toolCalls: [
932
+ reply_id: expect.any(String),
933
+ tool_calls: [
906
934
  {
907
935
  type: 'tool_call',
908
936
  id: '1',
909
937
  name: 'ExternalAndConfirmTool',
910
938
  input: '{"command": "rm -rf /"}',
939
+ state: 'allowed',
911
940
  },
912
941
  ],
913
942
  });
914
943
 
915
944
  // Verify agent state after user confirmation
916
945
  expect(await agent.toJSON()).toMatchObject({
917
- replyId: expect.any(String),
946
+ reply_id: expect.any(String),
918
947
  confirmedToolCallIds: ['1', '2'],
919
948
  curIter: 0,
920
949
  });
@@ -927,12 +956,14 @@ describe('Human-in-the-loop', () => {
927
956
  input: '{"command": "rm -rf /"}',
928
957
  name: 'ExternalAndConfirmTool',
929
958
  type: 'tool_call',
959
+ state: 'allowed',
930
960
  },
931
961
  {
932
962
  id: '2',
933
963
  input: '{"action": "delete database"}',
934
964
  name: 'ConfirmOnlyTool',
935
965
  type: 'tool_call',
966
+ state: 'allowed',
936
967
  },
937
968
  ],
938
969
  ]);
@@ -944,10 +975,10 @@ describe('Human-in-the-loop', () => {
944
975
  for await (const event of agent.replyStream({
945
976
  event: {
946
977
  id: 'xxx',
947
- createdAt: new Date().toISOString(),
978
+ created_at: new Date().toISOString(),
948
979
  type: EventType.EXTERNAL_EXECUTION_RESULT,
949
- replyId: agent.replyId,
950
- executionResults: [
980
+ reply_id: agent.replyId,
981
+ execution_results: [
951
982
  {
952
983
  type: 'tool_result',
953
984
  id: '1',
@@ -971,9 +1002,9 @@ describe('Human-in-the-loop', () => {
971
1002
  // because it was already confirmed in the previous step
972
1003
  expect(lastEvent).toMatchObject({
973
1004
  id: expect.any(String),
974
- type: EventType.RUN_FINISHED,
975
- createdAt: expect.any(String),
976
- replyId: agent.replyId,
1005
+ type: EventType.REPLY_END,
1006
+ created_at: expect.any(String),
1007
+ reply_id: agent.replyId,
977
1008
  });
978
1009
 
979
1010
  // Verify the final agent context includes all tool calls, their results, and the final text
@@ -984,12 +1015,14 @@ describe('Human-in-the-loop', () => {
984
1015
  input: '{"command": "rm -rf /"}',
985
1016
  name: 'ExternalAndConfirmTool',
986
1017
  type: 'tool_call',
1018
+ state: 'allowed',
987
1019
  },
988
1020
  {
989
1021
  id: '2',
990
1022
  input: '{"action": "delete database"}',
991
1023
  name: 'ConfirmOnlyTool',
992
1024
  type: 'tool_call',
1025
+ state: 'allowed',
993
1026
  },
994
1027
  {
995
1028
  id: '1',