@agentscope-ai/agentscope 0.0.2 → 0.0.3
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.
- package/LICENSE +202 -0
- package/dist/agent/index.d.mts +10 -10
- package/dist/agent/index.d.ts +10 -10
- package/dist/agent/index.js +94 -90
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/index.mjs +94 -90
- package/dist/agent/index.mjs.map +1 -1
- package/dist/{base-BOx3UzOl.d.mts → base-Bo8TzBQq.d.mts} +2 -2
- package/dist/{base-NX-knWOv.d.ts → base-Co-MzdN5.d.ts} +1 -1
- package/dist/{base-DYlBMCy_.d.mts → base-D9uCcDjZ.d.mts} +3 -3
- package/dist/{base-C7jwyH4Z.d.mts → base-Dh5vEBQD.d.mts} +1 -1
- package/dist/{base-Cwi4bjze.d.ts → base-TYjCCv7T.d.ts} +3 -3
- package/dist/{base-BoIps2RL.d.ts → base-t7G4uaR_.d.ts} +2 -2
- package/dist/{block-VsnHrllL.d.mts → block-7fd6byyN.d.mts} +2 -2
- package/dist/{block-VsnHrllL.d.ts → block-7fd6byyN.d.ts} +2 -2
- package/dist/event/index.d.mts +105 -89
- package/dist/event/index.d.ts +105 -89
- package/dist/event/index.js +8 -8
- package/dist/event/index.js.map +1 -1
- package/dist/event/index.mjs +8 -8
- package/dist/event/index.mjs.map +1 -1
- package/dist/formatter/index.d.mts +3 -3
- package/dist/formatter/index.d.ts +3 -3
- package/dist/formatter/index.js +17 -17
- package/dist/formatter/index.js.map +1 -1
- package/dist/formatter/index.mjs +17 -17
- package/dist/formatter/index.mjs.map +1 -1
- package/dist/{index-BTJDlKvQ.d.mts → index-BVNbIN62.d.mts} +1 -1
- package/dist/{index-BcatlwXQ.d.ts → index-DaopL-Vp.d.ts} +1 -1
- package/dist/mcp/index.d.mts +2 -2
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/index.mjs +1 -1
- package/dist/mcp/index.mjs.map +1 -1
- package/dist/message/index.d.mts +2 -2
- package/dist/message/index.d.ts +2 -2
- package/dist/message/index.js +39 -5
- package/dist/message/index.js.map +1 -1
- package/dist/message/index.mjs +36 -5
- package/dist/message/index.mjs.map +1 -1
- package/dist/{message-CkN21KaY.d.mts → message-CYnHiEVt.d.mts} +66 -43
- package/dist/{message-CzLeTlua.d.ts → message-DZN7LetB.d.ts} +66 -43
- package/dist/model/index.d.mts +5 -5
- package/dist/model/index.d.ts +5 -5
- package/dist/model/index.js +17 -17
- package/dist/model/index.js.map +1 -1
- package/dist/model/index.mjs +17 -17
- package/dist/model/index.mjs.map +1 -1
- package/dist/storage/index.d.mts +3 -3
- package/dist/storage/index.d.ts +3 -3
- package/dist/storage/index.js +4 -4
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/index.mjs +4 -4
- package/dist/storage/index.mjs.map +1 -1
- package/dist/tool/index.d.mts +4 -4
- package/dist/tool/index.d.ts +4 -4
- package/dist/{toolkit-CEpulFi0.d.ts → toolkit-BuMTkbGg.d.ts} +2 -2
- package/dist/{toolkit-CGEZSZPa.d.mts → toolkit-CH9qKAy9.d.mts} +2 -2
- package/package.json +87 -87
- package/src/agent/agent.test.ts +63 -63
- package/src/agent/agent.ts +101 -99
- package/src/agent/test-compression.ts +1 -1
- package/src/event/index.ts +96 -98
- package/src/formatter/base.ts +3 -3
- package/src/formatter/dashscope-chat-formatter.test.ts +8 -8
- package/src/formatter/dashscope-chat-formatter.ts +3 -3
- package/src/formatter/openai-chat-formatter.test.ts +4 -4
- package/src/formatter/openai-chat-formatter.ts +6 -6
- package/src/mcp/base.ts +1 -1
- package/src/message/block.ts +2 -2
- package/src/message/index.ts +9 -1
- package/src/message/message.test.ts +1 -1
- package/src/message/message.ts +101 -47
- package/src/permission/index.ts +13 -0
- package/src/storage/file-system.test.ts +3 -3
- package/src/storage/file-system.ts +4 -4
package/src/agent/agent.ts
CHANGED
|
@@ -14,10 +14,10 @@ import { ActingOptions, ObserveOptions, ReasoningOptions, ReplyOptions } from '.
|
|
|
14
14
|
import {
|
|
15
15
|
AgentEvent,
|
|
16
16
|
EventType,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
ModelCallEndEvent,
|
|
18
|
+
ModelCallStartEvent,
|
|
19
|
+
ReplyEndEvent,
|
|
20
|
+
ReplyStartEvent,
|
|
21
21
|
TextBlockDeltaEvent,
|
|
22
22
|
TextBlockEndEvent,
|
|
23
23
|
TextBlockStartEvent,
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
ToolCallDeltaEvent,
|
|
28
28
|
ToolCallEndEvent,
|
|
29
29
|
ToolCallStartEvent,
|
|
30
|
-
|
|
30
|
+
ToolResultDataDeltaEvent,
|
|
31
31
|
ToolResultEndEvent,
|
|
32
32
|
ToolResultStartEvent,
|
|
33
33
|
ToolResultTextDeltaEvent,
|
|
@@ -194,7 +194,7 @@ export class Agent {
|
|
|
194
194
|
agentId: this.name,
|
|
195
195
|
context: this.context,
|
|
196
196
|
metadata: {
|
|
197
|
-
|
|
197
|
+
reply_id: this.replyId,
|
|
198
198
|
curIter: this.curIter,
|
|
199
199
|
curSummary: this.curSummary,
|
|
200
200
|
},
|
|
@@ -383,47 +383,47 @@ export class Agent {
|
|
|
383
383
|
const event = options.event;
|
|
384
384
|
if (event.type === EventType.EXTERNAL_EXECUTION_RESULT) {
|
|
385
385
|
// Record the tool results into context and go on acting
|
|
386
|
-
this._saveToContext(event.
|
|
386
|
+
this._saveToContext(event.execution_results);
|
|
387
387
|
} else if (event.type === EventType.USER_CONFIRM_RESULT) {
|
|
388
|
-
for (const result of event.
|
|
388
|
+
for (const result of event.confirm_results) {
|
|
389
389
|
if (result.confirmed) {
|
|
390
|
-
this.confirmedToolCallIds.push(result.
|
|
390
|
+
this.confirmedToolCallIds.push(result.tool_call.id);
|
|
391
391
|
} else {
|
|
392
392
|
// If user rejected, add a rejection result and handle the pending tool calls
|
|
393
|
-
const rejectionRes = `<system-info>**Note** the user rejected the execution of tool "${result.
|
|
393
|
+
const rejectionRes = `<system-info>**Note** the user rejected the execution of tool "${result.tool_call.name}"!</system-info>`;
|
|
394
394
|
yield {
|
|
395
395
|
id: crypto.randomUUID(),
|
|
396
|
-
|
|
396
|
+
created_at: new Date().toISOString(),
|
|
397
397
|
type: EventType.TOOL_RESULT_START,
|
|
398
|
-
|
|
399
|
-
|
|
398
|
+
reply_id: this.replyId,
|
|
399
|
+
tool_call_id: result.tool_call.id,
|
|
400
400
|
} as ToolResultStartEvent;
|
|
401
401
|
yield {
|
|
402
402
|
id: crypto.randomUUID(),
|
|
403
|
-
|
|
403
|
+
created_at: new Date().toISOString(),
|
|
404
404
|
type: EventType.TOOL_RESULT_TEXT_DELTA,
|
|
405
|
-
|
|
406
|
-
|
|
405
|
+
reply_id: this.replyId,
|
|
406
|
+
tool_call_id: result.tool_call.id,
|
|
407
407
|
delta: rejectionRes,
|
|
408
408
|
} as ToolResultTextDeltaEvent;
|
|
409
409
|
yield {
|
|
410
410
|
id: crypto.randomUUID(),
|
|
411
|
-
|
|
411
|
+
created_at: new Date().toISOString(),
|
|
412
412
|
type: EventType.TOOL_RESULT_END,
|
|
413
|
-
|
|
414
|
-
|
|
413
|
+
reply_id: this.replyId,
|
|
414
|
+
tool_call_id: result.tool_call.id,
|
|
415
415
|
state: 'interrupted',
|
|
416
416
|
} as ToolResultEndEvent;
|
|
417
417
|
this._saveToContext([
|
|
418
418
|
{
|
|
419
419
|
type: 'tool_result',
|
|
420
|
-
id: result.
|
|
421
|
-
name: result.
|
|
420
|
+
id: result.tool_call.id,
|
|
421
|
+
name: result.tool_call.name,
|
|
422
422
|
output: [
|
|
423
423
|
{
|
|
424
424
|
id: crypto.randomUUID(),
|
|
425
425
|
type: 'text',
|
|
426
|
-
text: `<system-info>**Note** the user rejected the execution of tool "${result.
|
|
426
|
+
text: `<system-info>**Note** the user rejected the execution of tool "${result.tool_call.name}"!</system-info>`,
|
|
427
427
|
},
|
|
428
428
|
],
|
|
429
429
|
state: 'interrupted',
|
|
@@ -432,7 +432,9 @@ export class Agent {
|
|
|
432
432
|
}
|
|
433
433
|
}
|
|
434
434
|
// Remove the tool call from the awaiting state
|
|
435
|
-
const processedToolCallIds = event.
|
|
435
|
+
const processedToolCallIds = event.confirm_results.map(
|
|
436
|
+
result => result.tool_call.id
|
|
437
|
+
);
|
|
436
438
|
// Set the awaitingUserConfirmation flag to undefined for UI update
|
|
437
439
|
this.context.at(-1)?.content.forEach(content => {
|
|
438
440
|
if (content.type === 'tool_call' && processedToolCallIds.includes(content.id)) {
|
|
@@ -449,13 +451,13 @@ export class Agent {
|
|
|
449
451
|
// Yield the run started event
|
|
450
452
|
yield {
|
|
451
453
|
id: crypto.randomUUID(),
|
|
452
|
-
type: EventType.
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
454
|
+
type: EventType.REPLY_START,
|
|
455
|
+
created_at: new Date().toISOString(),
|
|
456
|
+
session_id: '',
|
|
457
|
+
reply_id: this.replyId,
|
|
456
458
|
name: this.name,
|
|
457
459
|
role: 'assistant',
|
|
458
|
-
} as
|
|
460
|
+
} as ReplyStartEvent;
|
|
459
461
|
}
|
|
460
462
|
|
|
461
463
|
// Store the incoming message into memory
|
|
@@ -490,10 +492,10 @@ export class Agent {
|
|
|
490
492
|
if (awaitingType) {
|
|
491
493
|
yield {
|
|
492
494
|
id: crypto.randomUUID(),
|
|
493
|
-
|
|
495
|
+
created_at: new Date().toISOString(),
|
|
494
496
|
type: awaitingType,
|
|
495
|
-
|
|
496
|
-
|
|
497
|
+
reply_id: this.replyId,
|
|
498
|
+
tool_calls: awaitingToolCalls,
|
|
497
499
|
};
|
|
498
500
|
|
|
499
501
|
return createMsg({
|
|
@@ -528,11 +530,11 @@ export class Agent {
|
|
|
528
530
|
// Yield the run finished event
|
|
529
531
|
yield {
|
|
530
532
|
id: crypto.randomUUID(),
|
|
531
|
-
type: EventType.
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
} as
|
|
533
|
+
type: EventType.REPLY_END,
|
|
534
|
+
created_at: new Date().toISOString(),
|
|
535
|
+
session_id: '',
|
|
536
|
+
reply_id: this.replyId,
|
|
537
|
+
} as ReplyEndEvent;
|
|
536
538
|
|
|
537
539
|
return createMsg({
|
|
538
540
|
id: this.replyId,
|
|
@@ -557,11 +559,11 @@ export class Agent {
|
|
|
557
559
|
const tools = this.toolkit.getJSONSchemas();
|
|
558
560
|
yield {
|
|
559
561
|
id: crypto.randomUUID(),
|
|
560
|
-
|
|
561
|
-
type: EventType.
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
} as
|
|
562
|
+
created_at: new Date().toISOString(),
|
|
563
|
+
type: EventType.MODEL_CALL_START,
|
|
564
|
+
reply_id: this.replyId,
|
|
565
|
+
model_name: this.model.modelName,
|
|
566
|
+
} as ModelCallStartEvent;
|
|
565
567
|
const res = await this.model.call({
|
|
566
568
|
messages: [
|
|
567
569
|
createMsg({
|
|
@@ -620,41 +622,41 @@ export class Agent {
|
|
|
620
622
|
if (blockIds.textBlockId) {
|
|
621
623
|
yield {
|
|
622
624
|
id: crypto.randomUUID(),
|
|
623
|
-
|
|
625
|
+
created_at: new Date().toISOString(),
|
|
624
626
|
type: EventType.TEXT_BLOCK_END,
|
|
625
|
-
|
|
626
|
-
|
|
627
|
+
reply_id: this.replyId,
|
|
628
|
+
block_id: blockIds.textBlockId,
|
|
627
629
|
} as TextBlockEndEvent;
|
|
628
630
|
}
|
|
629
631
|
if (blockIds.thinkingBlockId) {
|
|
630
632
|
yield {
|
|
631
633
|
id: crypto.randomUUID(),
|
|
632
|
-
|
|
634
|
+
created_at: new Date().toISOString(),
|
|
633
635
|
type: EventType.THINKING_BLOCK_END,
|
|
634
|
-
|
|
635
|
-
|
|
636
|
+
reply_id: this.replyId,
|
|
637
|
+
block_id: blockIds.thinkingBlockId,
|
|
636
638
|
} as ThinkingBlockEndEvent;
|
|
637
639
|
}
|
|
638
640
|
if (blockIds.toolCallIds.length > 0) {
|
|
639
|
-
for (const
|
|
641
|
+
for (const tool_call_id of blockIds.toolCallIds) {
|
|
640
642
|
yield {
|
|
641
643
|
id: crypto.randomUUID(),
|
|
642
|
-
|
|
644
|
+
created_at: new Date().toISOString(),
|
|
643
645
|
type: EventType.TOOL_CALL_END,
|
|
644
|
-
|
|
645
|
-
|
|
646
|
+
reply_id: this.replyId,
|
|
647
|
+
tool_call_id,
|
|
646
648
|
} as ToolCallEndEvent;
|
|
647
649
|
}
|
|
648
650
|
}
|
|
649
651
|
|
|
650
652
|
yield {
|
|
651
653
|
id: crypto.randomUUID(),
|
|
652
|
-
|
|
653
|
-
type: EventType.
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
} as
|
|
654
|
+
created_at: new Date().toISOString(),
|
|
655
|
+
type: EventType.MODEL_CALL_END,
|
|
656
|
+
reply_id: this.replyId,
|
|
657
|
+
input_tokens: completedResponse.usage?.inputTokens || 0,
|
|
658
|
+
output_tokens: completedResponse.usage?.outputTokens || 0,
|
|
659
|
+
} as ModelCallEndEvent;
|
|
658
660
|
|
|
659
661
|
return completedResponse;
|
|
660
662
|
}
|
|
@@ -672,10 +674,10 @@ export class Agent {
|
|
|
672
674
|
yield {
|
|
673
675
|
type: EventType.TOOL_RESULT_START,
|
|
674
676
|
id: crypto.randomUUID(),
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
677
|
+
created_at: new Date().toISOString(),
|
|
678
|
+
reply_id: this.replyId,
|
|
679
|
+
tool_call_id: options.toolCall.id,
|
|
680
|
+
tool_call_name: options.toolCall.name,
|
|
679
681
|
} as ToolResultStartEvent;
|
|
680
682
|
|
|
681
683
|
while (true) {
|
|
@@ -741,18 +743,18 @@ export class Agent {
|
|
|
741
743
|
responseId.textBlockId = crypto.randomUUID();
|
|
742
744
|
yield {
|
|
743
745
|
id: crypto.randomUUID(),
|
|
744
|
-
|
|
746
|
+
created_at: new Date().toISOString(),
|
|
745
747
|
type: EventType.TEXT_BLOCK_START,
|
|
746
|
-
|
|
747
|
-
|
|
748
|
+
reply_id: this.replyId,
|
|
749
|
+
block_id: responseId.textBlockId,
|
|
748
750
|
} as TextBlockStartEvent;
|
|
749
751
|
}
|
|
750
752
|
yield {
|
|
751
753
|
id: crypto.randomUUID(),
|
|
752
|
-
|
|
754
|
+
created_at: new Date().toISOString(),
|
|
753
755
|
type: EventType.TEXT_BLOCK_DELTA,
|
|
754
|
-
|
|
755
|
-
|
|
756
|
+
reply_id: this.replyId,
|
|
757
|
+
block_id: responseId.textBlockId,
|
|
756
758
|
delta: block.text,
|
|
757
759
|
} as TextBlockDeltaEvent;
|
|
758
760
|
break;
|
|
@@ -762,18 +764,18 @@ export class Agent {
|
|
|
762
764
|
responseId.thinkingBlockId = crypto.randomUUID();
|
|
763
765
|
yield {
|
|
764
766
|
id: crypto.randomUUID(),
|
|
765
|
-
|
|
767
|
+
created_at: new Date().toISOString(),
|
|
766
768
|
type: EventType.THINKING_BLOCK_START,
|
|
767
|
-
|
|
768
|
-
|
|
769
|
+
reply_id: this.replyId,
|
|
770
|
+
block_id: responseId.thinkingBlockId,
|
|
769
771
|
} as ThinkingBlockStartEvent;
|
|
770
772
|
}
|
|
771
773
|
yield {
|
|
772
774
|
id: crypto.randomUUID(),
|
|
773
|
-
|
|
775
|
+
created_at: new Date().toISOString(),
|
|
774
776
|
type: EventType.THINKING_BLOCK_DELTA,
|
|
775
|
-
|
|
776
|
-
|
|
777
|
+
reply_id: this.replyId,
|
|
778
|
+
block_id: responseId.thinkingBlockId,
|
|
777
779
|
delta: block.thinking,
|
|
778
780
|
} as ThinkingBlockDeltaEvent;
|
|
779
781
|
break;
|
|
@@ -784,19 +786,19 @@ export class Agent {
|
|
|
784
786
|
yield {
|
|
785
787
|
id: crypto.randomUUID(),
|
|
786
788
|
type: EventType.TOOL_CALL_START,
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
789
|
+
created_at: new Date().toISOString(),
|
|
790
|
+
reply_id: this.replyId,
|
|
791
|
+
tool_call_id: block.id,
|
|
792
|
+
tool_call_name: block.name,
|
|
791
793
|
} as ToolCallStartEvent;
|
|
792
794
|
}
|
|
793
795
|
yield {
|
|
794
796
|
id: crypto.randomUUID(),
|
|
795
|
-
|
|
797
|
+
created_at: new Date().toISOString(),
|
|
796
798
|
type: EventType.TOOL_CALL_DELTA,
|
|
797
799
|
delta: block.input,
|
|
798
|
-
|
|
799
|
-
|
|
800
|
+
reply_id: this.replyId,
|
|
801
|
+
tool_call_id: block.id,
|
|
800
802
|
} as ToolCallDeltaEvent;
|
|
801
803
|
}
|
|
802
804
|
}
|
|
@@ -816,10 +818,10 @@ export class Agent {
|
|
|
816
818
|
case 'text':
|
|
817
819
|
yield {
|
|
818
820
|
id: crypto.randomUUID(),
|
|
819
|
-
|
|
821
|
+
created_at: new Date().toISOString(),
|
|
820
822
|
type: EventType.TOOL_RESULT_TEXT_DELTA,
|
|
821
|
-
|
|
822
|
-
|
|
823
|
+
reply_id: this.replyId,
|
|
824
|
+
tool_call_id: toolCall.id,
|
|
823
825
|
delta: block.text,
|
|
824
826
|
} as ToolResultTextDeltaEvent;
|
|
825
827
|
break;
|
|
@@ -828,33 +830,33 @@ export class Agent {
|
|
|
828
830
|
if (block.source.type === 'base64') {
|
|
829
831
|
yield {
|
|
830
832
|
id: crypto.randomUUID(),
|
|
831
|
-
|
|
832
|
-
type: EventType.
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
833
|
+
created_at: new Date().toISOString(),
|
|
834
|
+
type: EventType.TOOL_RESULT_DATA_DELTA,
|
|
835
|
+
reply_id: this.replyId,
|
|
836
|
+
tool_call_id: toolCall.id,
|
|
837
|
+
media_type: block.source.media_type,
|
|
836
838
|
data: block.source.data,
|
|
837
|
-
} as
|
|
839
|
+
} as ToolResultDataDeltaEvent;
|
|
838
840
|
} else if (block.source.type === 'url') {
|
|
839
841
|
yield {
|
|
840
842
|
id: crypto.randomUUID(),
|
|
841
|
-
|
|
842
|
-
type: EventType.
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
843
|
+
created_at: new Date().toISOString(),
|
|
844
|
+
type: EventType.TOOL_RESULT_DATA_DELTA,
|
|
845
|
+
reply_id: this.replyId,
|
|
846
|
+
tool_call_id: toolCall.id,
|
|
847
|
+
media_type: block.source.media_type,
|
|
846
848
|
url: block.source.url,
|
|
847
|
-
} as
|
|
849
|
+
} as ToolResultDataDeltaEvent;
|
|
848
850
|
}
|
|
849
851
|
break;
|
|
850
852
|
}
|
|
851
853
|
}
|
|
852
854
|
yield {
|
|
853
855
|
id: crypto.randomUUID(),
|
|
854
|
-
|
|
856
|
+
created_at: new Date().toISOString(),
|
|
855
857
|
type: EventType.TOOL_RESULT_END,
|
|
856
|
-
|
|
857
|
-
|
|
858
|
+
reply_id: this.replyId,
|
|
859
|
+
tool_call_id: toolCall.id,
|
|
858
860
|
state: toolRes.state,
|
|
859
861
|
} as ToolResultEndEvent;
|
|
860
862
|
}
|
|
@@ -865,7 +867,7 @@ export class Agent {
|
|
|
865
867
|
*/
|
|
866
868
|
public async toJSON() {
|
|
867
869
|
return {
|
|
868
|
-
|
|
870
|
+
reply_id: this.replyId,
|
|
869
871
|
confirmedToolCallIds: this.confirmedToolCallIds,
|
|
870
872
|
curIter: this.curIter,
|
|
871
873
|
};
|