@agentica/core 0.20.0 → 0.22.0
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/README.md +115 -413
- package/lib/Agentica.d.ts +2 -1
- package/lib/Agentica.js +15 -13
- package/lib/Agentica.js.map +1 -1
- package/lib/MicroAgentica.d.ts +2 -1
- package/lib/MicroAgentica.js +16 -11
- package/lib/MicroAgentica.js.map +1 -1
- package/lib/context/AgenticaContext.d.ts +4 -4
- package/lib/context/MicroAgenticaContext.d.ts +2 -2
- package/lib/context/internal/AgenticaOperationComposer.js +1 -8
- package/lib/context/internal/AgenticaOperationComposer.js.map +1 -1
- package/lib/events/AgenticaEvent.d.ts +3 -1
- package/lib/events/AgenticaTextEvent.d.ts +2 -2
- package/lib/events/AgenticaUserInputEvent.d.ts +10 -0
- package/lib/events/AgenticaUserInputEvent.js +3 -0
- package/lib/events/AgenticaUserInputEvent.js.map +1 -0
- package/lib/events/MicroAgenticaEvent.d.ts +3 -1
- package/lib/factory/events.d.ts +7 -3
- package/lib/factory/events.js +29 -4
- package/lib/factory/events.js.map +1 -1
- package/lib/factory/histories.d.ts +6 -3
- package/lib/factory/histories.js +59 -32
- package/lib/factory/histories.js.map +1 -1
- package/lib/functional/assertMcpController.js +0 -2
- package/lib/functional/assertMcpController.js.map +1 -1
- package/lib/histories/AgenticaHistory.d.ts +3 -1
- package/lib/histories/AgenticaTextHistory.d.ts +2 -2
- package/lib/histories/AgenticaUserInputHistory.d.ts +80 -0
- package/lib/histories/AgenticaUserInputHistory.js +3 -0
- package/lib/histories/AgenticaUserInputHistory.js.map +1 -0
- package/lib/histories/MicroAgenticaHistory.d.ts +2 -1
- package/lib/index.mjs +138 -105
- package/lib/index.mjs.map +1 -1
- package/lib/json/IAgenticaEventJson.d.ts +8 -1
- package/lib/json/IAgenticaHistoryJson.d.ts +15 -3
- package/lib/orchestrate/call.js +3 -17
- package/lib/orchestrate/call.js.map +1 -1
- package/lib/orchestrate/cancel.js +1 -1
- package/lib/orchestrate/cancel.js.map +1 -1
- package/lib/orchestrate/execute.js +13 -7
- package/lib/orchestrate/execute.js.map +1 -1
- package/lib/orchestrate/initialize.js +2 -6
- package/lib/orchestrate/initialize.js.map +1 -1
- package/lib/orchestrate/select.js +2 -6
- package/lib/orchestrate/select.js.map +1 -1
- package/lib/structures/IAgenticaExecutor.d.ts +10 -6
- package/lib/structures/IMicroAgenticaExecutor.d.ts +4 -1
- package/lib/transformers/AgenticaEventTransformer.js +0 -1
- package/lib/transformers/AgenticaEventTransformer.js.map +1 -1
- package/package.json +2 -2
- package/src/Agentica.ts +21 -18
- package/src/MicroAgentica.ts +20 -16
- package/src/context/AgenticaContext.ts +4 -4
- package/src/context/MicroAgenticaContext.ts +2 -2
- package/src/context/internal/AgenticaOperationComposer.ts +5 -6
- package/src/events/AgenticaEvent.ts +4 -1
- package/src/events/AgenticaTextEvent.ts +2 -4
- package/src/events/AgenticaUserInputEvent.ts +12 -0
- package/src/events/MicroAgenticaEvent.ts +4 -1
- package/src/factory/events.ts +26 -8
- package/src/factory/histories.ts +76 -43
- package/src/functional/assertMcpController.ts +1 -2
- package/src/histories/AgenticaHistory.ts +4 -1
- package/src/histories/AgenticaTextHistory.ts +2 -4
- package/src/histories/AgenticaUserInputHistory.ts +88 -0
- package/src/histories/MicroAgenticaHistory.ts +3 -1
- package/src/json/IAgenticaEventJson.ts +9 -1
- package/src/json/IAgenticaHistoryJson.ts +16 -4
- package/src/orchestrate/call.ts +15 -17
- package/src/orchestrate/cancel.ts +1 -1
- package/src/orchestrate/execute.ts +13 -7
- package/src/orchestrate/initialize.ts +2 -6
- package/src/orchestrate/select.ts +2 -7
- package/src/structures/IAgenticaExecutor.ts +16 -8
- package/src/structures/IMicroAgenticaExecutor.ts +10 -4
- package/src/transformers/AgenticaEventTransformer.ts +0 -1
|
@@ -71,7 +71,6 @@ function assertMcpController(props) {
|
|
|
71
71
|
const { ListToolsResultSchema } = yield Promise.resolve().then(() => __importStar(require("@modelcontextprotocol/sdk/types.js")));
|
|
72
72
|
// get list of tools
|
|
73
73
|
const { tools } = yield props.client.request({ method: "tools/list" }, ListToolsResultSchema);
|
|
74
|
-
// eslint-disable-next-line ts/no-unsafe-assignment, ts/no-unsafe-call, ts/no-unsafe-member-access
|
|
75
74
|
const application = openapi_1.McpLlm.application({
|
|
76
75
|
model: props.model,
|
|
77
76
|
tools: (() => { const _io0 = input => "string" === typeof input.name && input.name.length <= 64 && (undefined === input.description || "string" === typeof input.description) && ("object" === typeof input.inputSchema && null !== input.inputSchema && _iu1(input.inputSchema)); const _io1 = input => (undefined === input.nullable || "boolean" === typeof input.nullable) && (undefined === input.properties || "object" === typeof input.properties && null !== input.properties && false === Array.isArray(input.properties) && _io2(input.properties)) && (undefined === input.required || Array.isArray(input.required) && input.required.every(elem => "string" === typeof elem)) && (null !== input.additionalProperties && (undefined === input.additionalProperties || "boolean" === typeof input.additionalProperties || "object" === typeof input.additionalProperties && null !== input.additionalProperties && false === Array.isArray(input.additionalProperties) && _iu0(input.additionalProperties))) && (undefined === input.maxProperties || "number" === typeof input.maxProperties) && (undefined === input.minProperties || "number" === typeof input.minProperties) && "object" === input.type && (undefined === input.title || "string" === typeof input.title) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.deprecated || "boolean" === typeof input.deprecated) && true && (null !== input.examples && (undefined === input.examples || (Array.isArray(input.examples) || "object" === typeof input.examples && null !== input.examples && false === Array.isArray(input.examples) && _io5(input.examples)))) && (undefined === input.$defs || "object" === typeof input.$defs && null !== input.$defs && false === Array.isArray(input.$defs) && _io2(input.$defs)); const _io2 = input => Object.keys(input).every(key => {
|
|
@@ -1693,7 +1692,6 @@ function assertMcpController(props) {
|
|
|
1693
1692
|
protocol: "mcp",
|
|
1694
1693
|
name: props.name,
|
|
1695
1694
|
client: props.client,
|
|
1696
|
-
// eslint-disable-next-line ts/no-unsafe-assignment
|
|
1697
1695
|
application,
|
|
1698
1696
|
};
|
|
1699
1697
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertMcpController.js","sourceRoot":"","sources":["../../src/functional/assertMcpController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,
|
|
1
|
+
{"version":3,"file":"assertMcpController.js","sourceRoot":"","sources":["../../src/functional/assertMcpController.ts"],"names":[],"mappings":"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"}
|
|
@@ -4,7 +4,8 @@ import type { AgenticaDescribeHistory } from "./AgenticaDescribeHistory";
|
|
|
4
4
|
import type { AgenticaExecuteHistory } from "./AgenticaExecuteHistory";
|
|
5
5
|
import type { AgenticaSelectHistory } from "./AgenticaSelectHistory";
|
|
6
6
|
import type { AgenticaTextHistory } from "./AgenticaTextHistory";
|
|
7
|
-
|
|
7
|
+
import type { AgenticaUserInputHistory } from "./AgenticaUserInputHistory";
|
|
8
|
+
export type AgenticaHistory<Model extends ILlmSchema.Model> = AgenticaCancelHistory<Model> | AgenticaDescribeHistory<Model> | AgenticaExecuteHistory<Model> | AgenticaSelectHistory<Model> | AgenticaTextHistory | AgenticaUserInputHistory;
|
|
8
9
|
export declare namespace AgenticaHistory {
|
|
9
10
|
type Type = AgenticaHistory<any>["type"];
|
|
10
11
|
interface Mapper<Model extends ILlmSchema.Model> {
|
|
@@ -13,5 +14,6 @@ export declare namespace AgenticaHistory {
|
|
|
13
14
|
execute: AgenticaExecuteHistory<Model>;
|
|
14
15
|
select: AgenticaSelectHistory<Model>;
|
|
15
16
|
text: AgenticaTextHistory;
|
|
17
|
+
user_input: AgenticaUserInputHistory;
|
|
16
18
|
}
|
|
17
19
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
|
|
2
2
|
import type { AgenticaHistoryBase } from "./AgenticaHistoryBase";
|
|
3
|
-
export interface AgenticaTextHistory
|
|
4
|
-
role:
|
|
3
|
+
export interface AgenticaTextHistory extends AgenticaHistoryBase<"text", IAgenticaHistoryJson.IText> {
|
|
4
|
+
role: "assistant";
|
|
5
5
|
text: string;
|
|
6
6
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
|
|
2
|
+
import type { AgenticaHistoryBase } from "./AgenticaHistoryBase";
|
|
3
|
+
export interface AgenticaUserInputHistory extends AgenticaHistoryBase<"user_input", IAgenticaHistoryJson.IUserInput> {
|
|
4
|
+
role: "user";
|
|
5
|
+
contents: Array<AgenticaUserInputHistory.Contents>;
|
|
6
|
+
}
|
|
7
|
+
export declare namespace AgenticaUserInputHistory {
|
|
8
|
+
type Contents = Contents.File | Contents.Image | Contents.InputAudio | Contents.Text;
|
|
9
|
+
namespace Contents {
|
|
10
|
+
interface ContentsBase<Type extends string> {
|
|
11
|
+
/**
|
|
12
|
+
* The type of the content part.
|
|
13
|
+
*/
|
|
14
|
+
type: Type;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Learn about
|
|
18
|
+
* [text inputs](https://platform.openai.com/docs/guides/text-generation).
|
|
19
|
+
*/
|
|
20
|
+
export interface Text extends ContentsBase<"text"> {
|
|
21
|
+
/**
|
|
22
|
+
* The text content.
|
|
23
|
+
*/
|
|
24
|
+
text: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
|
|
28
|
+
*/
|
|
29
|
+
export interface Image extends ContentsBase<"image_url"> {
|
|
30
|
+
image_url: {
|
|
31
|
+
/**
|
|
32
|
+
* Either a URL of the image or the base64 encoded image data.
|
|
33
|
+
*/
|
|
34
|
+
url: string;
|
|
35
|
+
/**
|
|
36
|
+
* Specifies the detail level of the image. Learn more in the
|
|
37
|
+
* [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).
|
|
38
|
+
*/
|
|
39
|
+
detail?: "auto" | "high" | "low";
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).
|
|
44
|
+
*/
|
|
45
|
+
export interface InputAudio extends ContentsBase<"input_audio"> {
|
|
46
|
+
input_audio: {
|
|
47
|
+
/**
|
|
48
|
+
* Base64 encoded audio data.
|
|
49
|
+
*/
|
|
50
|
+
data: string;
|
|
51
|
+
/**
|
|
52
|
+
* The format of the encoded audio data. Currently supports "wav" and "mp3".
|
|
53
|
+
*/
|
|
54
|
+
format: "wav" | "mp3";
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Learn about [file inputs](https://platform.openai.com/docs/guides/text) for text
|
|
59
|
+
* generation.
|
|
60
|
+
*/
|
|
61
|
+
export interface File extends ContentsBase<"file"> {
|
|
62
|
+
file: {
|
|
63
|
+
/**
|
|
64
|
+
* The base64 encoded file data, used when passing the file to the model as a
|
|
65
|
+
* string.
|
|
66
|
+
*/
|
|
67
|
+
file_data?: string;
|
|
68
|
+
/**
|
|
69
|
+
* The ID of an uploaded file to use as input.
|
|
70
|
+
*/
|
|
71
|
+
file_id?: string;
|
|
72
|
+
/**
|
|
73
|
+
* The name of the file, used when passing the file to the model as a string.
|
|
74
|
+
*/
|
|
75
|
+
filename?: string;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export {};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgenticaUserInputHistory.js","sourceRoot":"","sources":["../../src/histories/AgenticaUserInputHistory.ts"],"names":[],"mappings":""}
|
|
@@ -2,7 +2,8 @@ import type { ILlmSchema } from "@samchon/openapi";
|
|
|
2
2
|
import type { AgenticaDescribeHistory } from "./AgenticaDescribeHistory";
|
|
3
3
|
import type { AgenticaExecuteHistory } from "./AgenticaExecuteHistory";
|
|
4
4
|
import type { AgenticaTextHistory } from "./AgenticaTextHistory";
|
|
5
|
-
|
|
5
|
+
import type { AgenticaUserInputHistory } from "./AgenticaUserInputHistory";
|
|
6
|
+
export type MicroAgenticaHistory<Model extends ILlmSchema.Model> = AgenticaDescribeHistory<Model> | AgenticaExecuteHistory<Model> | AgenticaTextHistory | AgenticaUserInputHistory;
|
|
6
7
|
export declare namespace MicroAgenticaHistory {
|
|
7
8
|
type Type = MicroAgenticaHistory<any>["type"];
|
|
8
9
|
interface Mapper<Model extends ILlmSchema.Model> {
|
package/lib/index.mjs
CHANGED
|
@@ -273,12 +273,14 @@ const AgenticaTokenUsageAggregator = {
|
|
|
273
273
|
function decodeHistory(history) {
|
|
274
274
|
if (history.type === "describe") {
|
|
275
275
|
return [];
|
|
276
|
-
}
|
|
276
|
+
}
|
|
277
|
+
if (history.type === "text") {
|
|
277
278
|
return [ {
|
|
278
279
|
role: history.role,
|
|
279
280
|
content: history.text
|
|
280
281
|
} ];
|
|
281
|
-
}
|
|
282
|
+
}
|
|
283
|
+
if (history.type === "select" || history.type === "cancel") {
|
|
282
284
|
return [ {
|
|
283
285
|
role: "assistant",
|
|
284
286
|
tool_calls: [ {
|
|
@@ -300,44 +302,65 @@ function decodeHistory(history) {
|
|
|
300
302
|
content: ""
|
|
301
303
|
} ];
|
|
302
304
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
305
|
+
if (history.type === "execute") {
|
|
306
|
+
return [ {
|
|
307
|
+
role: "assistant",
|
|
308
|
+
tool_calls: [ {
|
|
309
|
+
type: "function",
|
|
310
|
+
id: history.id,
|
|
311
|
+
function: {
|
|
312
|
+
name: history.operation.name,
|
|
313
|
+
arguments: JSON.stringify(history.arguments)
|
|
314
|
+
}
|
|
315
|
+
} ]
|
|
316
|
+
}, {
|
|
317
|
+
role: "tool",
|
|
318
|
+
tool_call_id: history.id,
|
|
319
|
+
content: JSON.stringify({
|
|
320
|
+
function: {
|
|
321
|
+
protocol: history.operation.protocol,
|
|
322
|
+
description: history.operation.function.description,
|
|
323
|
+
parameters: history.operation.function.parameters,
|
|
324
|
+
output: history.operation.function.output,
|
|
325
|
+
...history.operation.protocol === "http" ? {
|
|
326
|
+
method: history.operation.function.method,
|
|
327
|
+
path: history.operation.function.path
|
|
328
|
+
} : {}
|
|
329
|
+
},
|
|
322
330
|
...history.operation.protocol === "http" ? {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
} : {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
331
|
+
status: history.value.status,
|
|
332
|
+
data: history.value.body
|
|
333
|
+
} : {
|
|
334
|
+
value: history.value
|
|
335
|
+
}
|
|
336
|
+
})
|
|
337
|
+
} ];
|
|
338
|
+
}
|
|
339
|
+
if (history.type === "user_input") {
|
|
340
|
+
return [ {
|
|
341
|
+
role: "user",
|
|
342
|
+
content: history.contents
|
|
343
|
+
} ];
|
|
344
|
+
}
|
|
345
|
+
throw new Error("Invalid history type");
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function createUserInputHistory(props) {
|
|
349
|
+
return {
|
|
350
|
+
type: "user_input",
|
|
351
|
+
role: "user",
|
|
352
|
+
contents: props.contents,
|
|
353
|
+
toJSON: () => ({
|
|
354
|
+
type: "user_input",
|
|
355
|
+
contents: props.contents
|
|
333
356
|
})
|
|
334
|
-
}
|
|
357
|
+
};
|
|
335
358
|
}
|
|
336
359
|
|
|
337
360
|
function createTextHistory(props) {
|
|
338
361
|
const prompt = {
|
|
339
362
|
type: "text",
|
|
340
|
-
role:
|
|
363
|
+
role: "assistant",
|
|
341
364
|
text: props.text
|
|
342
365
|
};
|
|
343
366
|
return {
|
|
@@ -414,6 +437,22 @@ function createInitializeEvent() {
|
|
|
414
437
|
};
|
|
415
438
|
}
|
|
416
439
|
|
|
440
|
+
function createUserInputEvent(props) {
|
|
441
|
+
return {
|
|
442
|
+
type: "user_input",
|
|
443
|
+
role: "user",
|
|
444
|
+
contents: props.contents,
|
|
445
|
+
join: async () => props.contents,
|
|
446
|
+
toJSON: () => ({
|
|
447
|
+
type: "user_input",
|
|
448
|
+
contents: props.contents
|
|
449
|
+
}),
|
|
450
|
+
toHistory: () => createUserInputHistory({
|
|
451
|
+
contents: props.contents
|
|
452
|
+
})
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
|
|
417
456
|
function createSelectEvent(props) {
|
|
418
457
|
return {
|
|
419
458
|
type: "select",
|
|
@@ -493,22 +532,22 @@ function createExecuteEvent(props) {
|
|
|
493
532
|
function createTextEvent(props) {
|
|
494
533
|
return {
|
|
495
534
|
type: "text",
|
|
496
|
-
role:
|
|
535
|
+
role: "assistant",
|
|
497
536
|
stream: props.stream,
|
|
498
537
|
join: props.join,
|
|
499
538
|
toJSON: () => ({
|
|
500
539
|
type: "text",
|
|
501
|
-
role:
|
|
540
|
+
role: "assistant",
|
|
502
541
|
done: props.done(),
|
|
503
542
|
text: props.get()
|
|
504
543
|
}),
|
|
505
544
|
toHistory: () => ({
|
|
506
545
|
type: "text",
|
|
507
|
-
role:
|
|
546
|
+
role: "assistant",
|
|
508
547
|
text: props.get(),
|
|
509
548
|
toJSON: () => ({
|
|
510
549
|
type: "text",
|
|
511
|
-
role:
|
|
550
|
+
role: "assistant",
|
|
512
551
|
text: props.get()
|
|
513
552
|
})
|
|
514
553
|
})
|
|
@@ -560,6 +599,40 @@ function createResponseEvent(props) {
|
|
|
560
599
|
};
|
|
561
600
|
}
|
|
562
601
|
|
|
602
|
+
function createOperationSelection(props) {
|
|
603
|
+
return {
|
|
604
|
+
operation: props.operation,
|
|
605
|
+
reason: props.reason,
|
|
606
|
+
toJSON: () => ({
|
|
607
|
+
operation: props.operation.toJSON(),
|
|
608
|
+
reason: props.reason
|
|
609
|
+
})
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
var index$2 = Object.freeze({
|
|
614
|
+
__proto__: null,
|
|
615
|
+
createCallEvent,
|
|
616
|
+
createCancelEvent,
|
|
617
|
+
createCancelHistory,
|
|
618
|
+
createDescribeEvent,
|
|
619
|
+
createDescribeHistory,
|
|
620
|
+
createExecuteEvent,
|
|
621
|
+
createExecuteHistory,
|
|
622
|
+
createInitializeEvent,
|
|
623
|
+
createOperationSelection,
|
|
624
|
+
createRequestEvent,
|
|
625
|
+
createResponseEvent,
|
|
626
|
+
createSelectEvent,
|
|
627
|
+
createSelectHistory,
|
|
628
|
+
createTextEvent,
|
|
629
|
+
createTextHistory,
|
|
630
|
+
createUserInputEvent,
|
|
631
|
+
createUserInputHistory,
|
|
632
|
+
createValidateEvent,
|
|
633
|
+
decodeHistory
|
|
634
|
+
});
|
|
635
|
+
|
|
563
636
|
var AgenticaConstant;
|
|
564
637
|
|
|
565
638
|
(function(AgenticaConstant) {
|
|
@@ -617,17 +690,6 @@ function isAgenticaContext(ctx) {
|
|
|
617
690
|
return typeof ctx.initialize === "function";
|
|
618
691
|
}
|
|
619
692
|
|
|
620
|
-
function createOperationSelection(props) {
|
|
621
|
-
return {
|
|
622
|
-
operation: props.operation,
|
|
623
|
-
reason: props.reason,
|
|
624
|
-
toJSON: () => ({
|
|
625
|
-
operation: props.operation.toJSON(),
|
|
626
|
-
reason: props.reason
|
|
627
|
-
})
|
|
628
|
-
};
|
|
629
|
-
}
|
|
630
|
-
|
|
631
693
|
var ByteArrayUtil;
|
|
632
694
|
|
|
633
695
|
(function(ByteArrayUtil) {
|
|
@@ -1251,7 +1313,7 @@ async function call(ctx, operations) {
|
|
|
1251
1313
|
content: AgenticaDefaultPrompt.write(ctx.config)
|
|
1252
1314
|
}, ...ctx.histories.map(decodeHistory).flat(), {
|
|
1253
1315
|
role: "user",
|
|
1254
|
-
content: ctx.prompt.
|
|
1316
|
+
content: ctx.prompt.contents
|
|
1255
1317
|
}, ...ctx.config?.systemPrompt?.execute === null ? [] : [ {
|
|
1256
1318
|
role: "system",
|
|
1257
1319
|
content: ctx.config?.systemPrompt?.execute?.(ctx.histories) ?? AgenticaSystemPrompt.EXECUTE
|
|
@@ -1323,11 +1385,9 @@ async function call(ctx, operations) {
|
|
|
1323
1385
|
if (choice.message.role === "assistant" && choice.message.content != null && choice.message.content.length !== 0) {
|
|
1324
1386
|
closures.push((async () => {
|
|
1325
1387
|
const value = createTextHistory({
|
|
1326
|
-
role: "assistant",
|
|
1327
1388
|
text: choice.message.content
|
|
1328
1389
|
});
|
|
1329
1390
|
ctx.dispatch(createTextEvent({
|
|
1330
|
-
role: "assistant",
|
|
1331
1391
|
get: () => value.text,
|
|
1332
1392
|
done: () => true,
|
|
1333
1393
|
stream: toAsyncGenerator(value.text),
|
|
@@ -1528,7 +1588,7 @@ async function correct(ctx, call, retry, error) {
|
|
|
1528
1588
|
content: AgenticaDefaultPrompt.write(ctx.config)
|
|
1529
1589
|
}, ...ctx.histories.map(decodeHistory).flat(), {
|
|
1530
1590
|
role: "user",
|
|
1531
|
-
content: ctx.prompt.
|
|
1591
|
+
content: ctx.prompt.contents
|
|
1532
1592
|
}, ...ctx.config?.systemPrompt?.execute === null ? [] : [ {
|
|
1533
1593
|
role: "system",
|
|
1534
1594
|
content: ctx.config?.systemPrompt?.execute?.(ctx.histories) ?? AgenticaSystemPrompt.EXECUTE
|
|
@@ -1759,7 +1819,7 @@ async function step$1(ctx, operations, retry, failures) {
|
|
|
1759
1819
|
}))))
|
|
1760
1820
|
}, ...ctx.histories.map(decodeHistory).flat(), {
|
|
1761
1821
|
role: "user",
|
|
1762
|
-
content: ctx.prompt.
|
|
1822
|
+
content: ctx.prompt.contents
|
|
1763
1823
|
}, {
|
|
1764
1824
|
role: "system",
|
|
1765
1825
|
content: ctx.config?.systemPrompt?.cancel?.(ctx.histories) ?? AgenticaSystemPrompt.CANCEL
|
|
@@ -3756,7 +3816,7 @@ async function initialize(ctx) {
|
|
|
3756
3816
|
content: AgenticaDefaultPrompt.write(ctx.config)
|
|
3757
3817
|
}, ...ctx.histories.map(decodeHistory).flat(), {
|
|
3758
3818
|
role: "user",
|
|
3759
|
-
content: ctx.prompt.
|
|
3819
|
+
content: ctx.prompt.contents
|
|
3760
3820
|
}, {
|
|
3761
3821
|
role: "system",
|
|
3762
3822
|
content: ctx.config?.systemPrompt?.initialize?.(ctx.histories) ?? AgenticaSystemPrompt.INITIALIZE
|
|
@@ -3796,7 +3856,6 @@ async function initialize(ctx) {
|
|
|
3796
3856
|
};
|
|
3797
3857
|
mpsc.produce(choice.delta.content);
|
|
3798
3858
|
ctx.dispatch(createTextEvent({
|
|
3799
|
-
role: "assistant",
|
|
3800
3859
|
stream: streamDefaultReaderToAsyncGenerator(mpsc.consumer.getReader()),
|
|
3801
3860
|
done: () => mpsc.done(),
|
|
3802
3861
|
get: () => textContext[choice.index].content,
|
|
@@ -3821,7 +3880,6 @@ async function initialize(ctx) {
|
|
|
3821
3880
|
for (const choice of completion.choices) {
|
|
3822
3881
|
if (choice.message.role === "assistant" && choice.message.content != null && choice.message.content.length !== 0) {
|
|
3823
3882
|
prompts.push(createTextHistory({
|
|
3824
|
-
role: "assistant",
|
|
3825
3883
|
text: choice.message.content
|
|
3826
3884
|
}));
|
|
3827
3885
|
}
|
|
@@ -4010,7 +4068,7 @@ async function step(ctx, operations, retry, failures) {
|
|
|
4010
4068
|
}))))
|
|
4011
4069
|
}, ...ctx.histories.map(decodeHistory).flat(), {
|
|
4012
4070
|
role: "user",
|
|
4013
|
-
content: ctx.prompt.
|
|
4071
|
+
content: ctx.prompt.contents
|
|
4014
4072
|
}, {
|
|
4015
4073
|
role: "system",
|
|
4016
4074
|
content: ctx.config?.systemPrompt?.select?.(ctx.histories) ?? AgenticaSystemPrompt.SELECT
|
|
@@ -4153,12 +4211,10 @@ async function step(ctx, operations, retry, failures) {
|
|
|
4153
4211
|
}
|
|
4154
4212
|
if (choice.message.role === "assistant" && choice.message.content != null && choice.message.content.length !== 0) {
|
|
4155
4213
|
const text = createTextHistory({
|
|
4156
|
-
role: "assistant",
|
|
4157
4214
|
text: choice.message.content
|
|
4158
4215
|
});
|
|
4159
4216
|
prompts.push(text);
|
|
4160
4217
|
ctx.dispatch(createTextEvent({
|
|
4161
|
-
role: "assistant",
|
|
4162
4218
|
stream: toAsyncGenerator(text.text),
|
|
4163
4219
|
join: async () => Promise.resolve(text.text),
|
|
4164
4220
|
done: () => true,
|
|
@@ -4194,10 +4250,10 @@ function execute(executor) {
|
|
|
4194
4250
|
return async ctx => {
|
|
4195
4251
|
const histories = [];
|
|
4196
4252
|
if (ctx.ready() === false) {
|
|
4197
|
-
if (executor?.initialize
|
|
4253
|
+
if (executor?.initialize !== true && typeof executor?.initialize !== "function") {
|
|
4198
4254
|
await ctx.initialize();
|
|
4199
4255
|
} else {
|
|
4200
|
-
histories.push(...await (executor?.initialize
|
|
4256
|
+
histories.push(...await (typeof executor?.initialize === "function" ? executor.initialize : initialize)(ctx));
|
|
4201
4257
|
if (ctx.ready() === false) {
|
|
4202
4258
|
return histories;
|
|
4203
4259
|
}
|
|
@@ -4214,7 +4270,9 @@ function execute(executor) {
|
|
|
4214
4270
|
const prompts = await (executor?.call ?? call)(ctx, ctx.stack.map((s => s.operation)));
|
|
4215
4271
|
histories.push(...prompts);
|
|
4216
4272
|
const executes = prompts.filter((prompt => prompt.type === "execute"));
|
|
4217
|
-
|
|
4273
|
+
if (executor?.describe !== null && executor?.describe !== false) {
|
|
4274
|
+
histories.push(...await (typeof executor?.describe === "function" ? executor.describe : describe)(ctx, executes));
|
|
4275
|
+
}
|
|
4218
4276
|
if (executes.length === 0 || ctx.stack.length === 0) {
|
|
4219
4277
|
break;
|
|
4220
4278
|
}
|
|
@@ -4345,23 +4403,21 @@ class Agentica {
|
|
|
4345
4403
|
});
|
|
4346
4404
|
}
|
|
4347
4405
|
async conversate(content) {
|
|
4348
|
-
const
|
|
4349
|
-
|
|
4350
|
-
|
|
4406
|
+
const prompt = createUserInputHistory({
|
|
4407
|
+
contents: Array.isArray(content) ? content : typeof content === "string" ? [ {
|
|
4408
|
+
type: "text",
|
|
4409
|
+
text: content
|
|
4410
|
+
} ] : [ content ]
|
|
4351
4411
|
});
|
|
4352
|
-
this.dispatch(
|
|
4353
|
-
|
|
4354
|
-
stream: toAsyncGenerator(content),
|
|
4355
|
-
done: () => true,
|
|
4356
|
-
get: () => content,
|
|
4357
|
-
join: async () => Promise.resolve(content)
|
|
4412
|
+
this.dispatch(createUserInputEvent({
|
|
4413
|
+
contents: prompt.contents
|
|
4358
4414
|
})).catch((() => {}));
|
|
4359
4415
|
const newbie = await this.executor_(this.getContext({
|
|
4360
|
-
prompt
|
|
4416
|
+
prompt,
|
|
4361
4417
|
usage: this.token_usage_
|
|
4362
4418
|
}));
|
|
4363
|
-
this.histories_.push(
|
|
4364
|
-
return [
|
|
4419
|
+
this.histories_.push(prompt, ...newbie);
|
|
4420
|
+
return [ prompt, ...newbie ];
|
|
4365
4421
|
}
|
|
4366
4422
|
getConfig() {
|
|
4367
4423
|
return this.props.config;
|
|
@@ -4470,27 +4526,6 @@ class Agentica {
|
|
|
4470
4526
|
}
|
|
4471
4527
|
}
|
|
4472
4528
|
|
|
4473
|
-
var index$2 = Object.freeze({
|
|
4474
|
-
__proto__: null,
|
|
4475
|
-
createCallEvent,
|
|
4476
|
-
createCancelEvent,
|
|
4477
|
-
createCancelHistory,
|
|
4478
|
-
createDescribeEvent,
|
|
4479
|
-
createDescribeHistory,
|
|
4480
|
-
createExecuteEvent,
|
|
4481
|
-
createExecuteHistory,
|
|
4482
|
-
createInitializeEvent,
|
|
4483
|
-
createOperationSelection,
|
|
4484
|
-
createRequestEvent,
|
|
4485
|
-
createResponseEvent,
|
|
4486
|
-
createSelectEvent,
|
|
4487
|
-
createSelectHistory,
|
|
4488
|
-
createTextEvent,
|
|
4489
|
-
createTextHistory,
|
|
4490
|
-
createValidateEvent,
|
|
4491
|
-
decodeHistory
|
|
4492
|
-
});
|
|
4493
|
-
|
|
4494
4529
|
function assertHttpLlmApplication(props) {
|
|
4495
4530
|
return HttpLlm.application({
|
|
4496
4531
|
model: props.model,
|
|
@@ -23187,16 +23222,14 @@ class MicroAgentica {
|
|
|
23187
23222
|
});
|
|
23188
23223
|
}
|
|
23189
23224
|
async conversate(content) {
|
|
23190
|
-
const talk =
|
|
23191
|
-
|
|
23192
|
-
|
|
23225
|
+
const talk = createUserInputHistory({
|
|
23226
|
+
contents: Array.isArray(content) ? content : typeof content === "string" ? [ {
|
|
23227
|
+
type: "text",
|
|
23228
|
+
text: content
|
|
23229
|
+
} ] : [ content ]
|
|
23193
23230
|
});
|
|
23194
|
-
this.dispatch(
|
|
23195
|
-
|
|
23196
|
-
stream: toAsyncGenerator(content),
|
|
23197
|
-
done: () => true,
|
|
23198
|
-
get: () => content,
|
|
23199
|
-
join: async () => Promise.resolve(content)
|
|
23231
|
+
this.dispatch(createUserInputEvent({
|
|
23232
|
+
contents: talk.contents
|
|
23200
23233
|
})).catch((() => {}));
|
|
23201
23234
|
const ctx = this.getContext({
|
|
23202
23235
|
prompt: talk,
|
|
@@ -23204,7 +23237,7 @@ class MicroAgentica {
|
|
|
23204
23237
|
});
|
|
23205
23238
|
const histories = await call(ctx, this.operations_.array);
|
|
23206
23239
|
const executes = histories.filter((p => p.type === "execute"));
|
|
23207
|
-
if (executes.length) {
|
|
23240
|
+
if (executes.length && ctx.config?.executor?.describe !== null && ctx.config?.executor?.describe !== false) {
|
|
23208
23241
|
histories.push(...await describe(ctx, executes));
|
|
23209
23242
|
}
|
|
23210
23243
|
this.histories_.push(talk, ...histories);
|