@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
package/src/orchestrate/call.ts
CHANGED
|
@@ -54,7 +54,7 @@ export async function call<Model extends ILlmSchema.Model>(
|
|
|
54
54
|
// USER INPUT
|
|
55
55
|
{
|
|
56
56
|
role: "user",
|
|
57
|
-
content: ctx.prompt.
|
|
57
|
+
content: ctx.prompt.contents,
|
|
58
58
|
},
|
|
59
59
|
// SYSTEM PROMPT
|
|
60
60
|
...(ctx.config?.systemPrompt?.execute === null
|
|
@@ -72,13 +72,13 @@ export async function call<Model extends ILlmSchema.Model>(
|
|
|
72
72
|
type: "function",
|
|
73
73
|
function: {
|
|
74
74
|
name: s.name,
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
description: s.function.description,
|
|
77
77
|
parameters: (
|
|
78
78
|
"separated" in s.function
|
|
79
|
-
|
|
79
|
+
|
|
80
80
|
&& s.function.separated !== undefined
|
|
81
|
-
|
|
81
|
+
|
|
82
82
|
? (s.function.separated.llm
|
|
83
83
|
?? ({
|
|
84
84
|
type: "object",
|
|
@@ -87,7 +87,7 @@ export async function call<Model extends ILlmSchema.Model>(
|
|
|
87
87
|
additionalProperties: false,
|
|
88
88
|
$defs: {},
|
|
89
89
|
} satisfies IChatGptSchema.IParameters))
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
: s.function.parameters) as Record<string, any>,
|
|
92
92
|
},
|
|
93
93
|
}) as OpenAI.ChatCompletionTool,
|
|
@@ -181,13 +181,11 @@ export async function call<Model extends ILlmSchema.Model>(
|
|
|
181
181
|
&& choice.message.content.length !== 0
|
|
182
182
|
) {
|
|
183
183
|
closures.push(async () => {
|
|
184
|
-
const value: AgenticaTextHistory = createTextHistory(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
});
|
|
184
|
+
const value: AgenticaTextHistory = createTextHistory(
|
|
185
|
+
{ text: choice.message.content! },
|
|
186
|
+
);
|
|
188
187
|
ctx.dispatch(
|
|
189
188
|
createTextEvent({
|
|
190
|
-
role: "assistant",
|
|
191
189
|
get: () => value.text,
|
|
192
190
|
done: () => true,
|
|
193
191
|
stream: toAsyncGenerator(value.text),
|
|
@@ -444,9 +442,9 @@ async function executeMcpOperation<Model extends ILlmSchema.Model>(
|
|
|
444
442
|
operationArguments: Record<string, unknown>,
|
|
445
443
|
): Promise<unknown> {
|
|
446
444
|
return operation.controller.client.callTool({
|
|
447
|
-
|
|
445
|
+
|
|
448
446
|
method: operation.function.name,
|
|
449
|
-
|
|
447
|
+
|
|
450
448
|
name: operation.function.name,
|
|
451
449
|
arguments: operationArguments,
|
|
452
450
|
}).then(v => v.content);
|
|
@@ -473,7 +471,7 @@ async function correct<Model extends ILlmSchema.Model>(
|
|
|
473
471
|
// USER INPUT
|
|
474
472
|
{
|
|
475
473
|
role: "user",
|
|
476
|
-
content: ctx.prompt.
|
|
474
|
+
content: ctx.prompt.contents,
|
|
477
475
|
},
|
|
478
476
|
// TYPE CORRECTION
|
|
479
477
|
...(ctx.config?.systemPrompt?.execute === null
|
|
@@ -518,7 +516,7 @@ async function correct<Model extends ILlmSchema.Model>(
|
|
|
518
516
|
type: "function",
|
|
519
517
|
function: {
|
|
520
518
|
name: call.operation.name,
|
|
521
|
-
|
|
519
|
+
|
|
522
520
|
description: call.operation.function.description,
|
|
523
521
|
/**
|
|
524
522
|
* @TODO fix it
|
|
@@ -526,9 +524,9 @@ async function correct<Model extends ILlmSchema.Model>(
|
|
|
526
524
|
*/
|
|
527
525
|
parameters: (
|
|
528
526
|
"separated" in call.operation.function
|
|
529
|
-
|
|
527
|
+
|
|
530
528
|
&& call.operation.function.separated !== undefined
|
|
531
|
-
|
|
529
|
+
|
|
532
530
|
? (call.operation.function.separated?.llm
|
|
533
531
|
?? ({
|
|
534
532
|
$defs: {},
|
|
@@ -537,7 +535,7 @@ async function correct<Model extends ILlmSchema.Model>(
|
|
|
537
535
|
additionalProperties: false,
|
|
538
536
|
required: [],
|
|
539
537
|
} satisfies IChatGptSchema.IParameters))
|
|
540
|
-
|
|
538
|
+
|
|
541
539
|
: call.operation.function.parameters) as unknown as Record<string, unknown>,
|
|
542
540
|
},
|
|
543
541
|
},
|
|
@@ -17,13 +17,15 @@ export function execute<Model extends ILlmSchema.Model>(executor: Partial<IAgent
|
|
|
17
17
|
|
|
18
18
|
// FUNCTIONS ARE NOT LISTED YET
|
|
19
19
|
if (ctx.ready() === false) {
|
|
20
|
-
if (executor?.initialize
|
|
20
|
+
if (executor?.initialize !== true && typeof executor?.initialize !== "function") {
|
|
21
21
|
await ctx.initialize();
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
24
|
histories.push(
|
|
25
25
|
...(await (
|
|
26
|
-
executor?.initialize
|
|
26
|
+
typeof executor?.initialize === "function"
|
|
27
|
+
? executor.initialize
|
|
28
|
+
: initialize
|
|
27
29
|
)(ctx)),
|
|
28
30
|
);
|
|
29
31
|
if (ctx.ready() === false) {
|
|
@@ -63,11 +65,15 @@ export function execute<Model extends ILlmSchema.Model>(executor: Partial<IAgent
|
|
|
63
65
|
const executes: AgenticaExecuteHistory<Model>[] = prompts.filter(
|
|
64
66
|
prompt => prompt.type === "execute",
|
|
65
67
|
);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
if (executor?.describe !== null && executor?.describe !== false) {
|
|
69
|
+
histories.push(
|
|
70
|
+
...(await (
|
|
71
|
+
typeof executor?.describe === "function"
|
|
72
|
+
? executor.describe
|
|
73
|
+
: describe
|
|
74
|
+
)(ctx, executes)),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
71
77
|
if (executes.length === 0 || ctx.stack.length === 0) {
|
|
72
78
|
break;
|
|
73
79
|
}
|
|
@@ -36,7 +36,7 @@ export async function initialize<Model extends ILlmSchema.Model>(ctx: AgenticaCo
|
|
|
36
36
|
// USER INPUT
|
|
37
37
|
{
|
|
38
38
|
role: "user",
|
|
39
|
-
content: ctx.prompt.
|
|
39
|
+
content: ctx.prompt.contents,
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
42
|
// SYSTEM PROMPT
|
|
@@ -108,7 +108,6 @@ export async function initialize<Model extends ILlmSchema.Model>(ctx: AgenticaCo
|
|
|
108
108
|
|
|
109
109
|
ctx.dispatch(
|
|
110
110
|
createTextEvent({
|
|
111
|
-
role: "assistant",
|
|
112
111
|
stream: streamDefaultReaderToAsyncGenerator(mpsc.consumer.getReader()),
|
|
113
112
|
done: () => mpsc.done(),
|
|
114
113
|
get: () => textContext[choice.index]!.content,
|
|
@@ -145,10 +144,7 @@ export async function initialize<Model extends ILlmSchema.Model>(ctx: AgenticaCo
|
|
|
145
144
|
&& choice.message.content.length !== 0
|
|
146
145
|
) {
|
|
147
146
|
prompts.push(
|
|
148
|
-
createTextHistory({
|
|
149
|
-
role: "assistant",
|
|
150
|
-
text: choice.message.content,
|
|
151
|
-
}),
|
|
147
|
+
createTextHistory({ text: choice.message.content }),
|
|
152
148
|
);
|
|
153
149
|
}
|
|
154
150
|
}
|
|
@@ -13,7 +13,6 @@ import type { __IChatSelectFunctionsApplication } from "../context/internal/__IC
|
|
|
13
13
|
import type { AgenticaEvent } from "../events/AgenticaEvent";
|
|
14
14
|
import type { AgenticaHistory } from "../histories/AgenticaHistory";
|
|
15
15
|
import type { AgenticaSelectHistory } from "../histories/AgenticaSelectHistory";
|
|
16
|
-
import type { AgenticaTextHistory } from "../histories/AgenticaTextHistory";
|
|
17
16
|
|
|
18
17
|
import { AgenticaConstant } from "../constants/AgenticaConstant";
|
|
19
18
|
import { AgenticaDefaultPrompt } from "../constants/AgenticaDefaultPrompt";
|
|
@@ -145,7 +144,7 @@ async function step<Model extends ILlmSchema.Model>(ctx: AgenticaContext<Model>,
|
|
|
145
144
|
// USER INPUT
|
|
146
145
|
{
|
|
147
146
|
role: "user",
|
|
148
|
-
content: ctx.prompt.
|
|
147
|
+
content: ctx.prompt.contents,
|
|
149
148
|
},
|
|
150
149
|
// SYSTEM PROMPT
|
|
151
150
|
{
|
|
@@ -260,15 +259,11 @@ async function step<Model extends ILlmSchema.Model>(ctx: AgenticaContext<Model>,
|
|
|
260
259
|
&& choice.message.content != null
|
|
261
260
|
&& choice.message.content.length !== 0
|
|
262
261
|
) {
|
|
263
|
-
const text
|
|
264
|
-
role: "assistant",
|
|
265
|
-
text: choice.message.content,
|
|
266
|
-
});
|
|
262
|
+
const text = createTextHistory({ text: choice.message.content });
|
|
267
263
|
prompts.push(text);
|
|
268
264
|
|
|
269
265
|
ctx.dispatch(
|
|
270
266
|
createTextEvent({
|
|
271
|
-
role: "assistant",
|
|
272
267
|
stream: toAsyncGenerator(text.text),
|
|
273
268
|
join: async () => Promise.resolve(text.text),
|
|
274
269
|
done: () => true,
|
|
@@ -49,15 +49,17 @@ export interface IAgenticaExecutor<Model extends ILlmSchema.Model> {
|
|
|
49
49
|
* conversate with the user.
|
|
50
50
|
*
|
|
51
51
|
* By the way, if you wanna skip the `initialize` agent, you can
|
|
52
|
-
* do it by configuring the {@link
|
|
53
|
-
* `null` value. In that case, the `initialize`
|
|
54
|
-
* called, and {@link Agentica} just starts from the
|
|
55
|
-
* agent.
|
|
52
|
+
* do it by configuring the {@link IAgenticaExecutor.initialize} as
|
|
53
|
+
* `undefined`, `false` or `null` value. In that case, the `initialize`
|
|
54
|
+
* agent will never be called, and {@link Agentica} just starts from the
|
|
55
|
+
* {@link select} agent.
|
|
56
56
|
*
|
|
57
57
|
* @param ctx Context of the agent
|
|
58
58
|
* @returns List of prompts generated by the initializer
|
|
59
|
+
* @default false
|
|
59
60
|
*/
|
|
60
61
|
initialize:
|
|
62
|
+
| boolean
|
|
61
63
|
| null
|
|
62
64
|
| ((ctx: AgenticaContext<Model>) => Promise<AgenticaHistory<Model>[]>);
|
|
63
65
|
|
|
@@ -124,14 +126,20 @@ export interface IAgenticaExecutor<Model extends ILlmSchema.Model> {
|
|
|
124
126
|
* `Describe` agent explains the results of the function callings
|
|
125
127
|
* to the user as markdown content.
|
|
126
128
|
*
|
|
129
|
+
* If you configure this property as `false` or `null`, the describer
|
|
130
|
+
* agent will never be used.
|
|
131
|
+
*
|
|
127
132
|
* @param ctx Context of the agent
|
|
128
133
|
* @param executes List of function calling results
|
|
129
134
|
* @returns List of prompts generated by the describer
|
|
130
135
|
*/
|
|
131
|
-
describe:
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
136
|
+
describe:
|
|
137
|
+
| boolean
|
|
138
|
+
| null
|
|
139
|
+
| ((
|
|
140
|
+
ctx: AgenticaContext<Model>,
|
|
141
|
+
executes: AgenticaExecuteHistory<Model>[],
|
|
142
|
+
) => Promise<AgenticaHistory<Model>[]>);
|
|
135
143
|
|
|
136
144
|
/**
|
|
137
145
|
* Function canceler agent.
|
|
@@ -52,12 +52,18 @@ export interface IMicroAgenticaExecutor<Model extends ILlmSchema.Model> {
|
|
|
52
52
|
* `Describe` agent explains the results of the function callings
|
|
53
53
|
* to the user as markdown content.
|
|
54
54
|
*
|
|
55
|
+
* If you configure this property as `false` or `null`, the describer
|
|
56
|
+
* agent never be used.
|
|
57
|
+
*
|
|
55
58
|
* @param ctx Context of the agent
|
|
56
59
|
* @param executes List of function calling results
|
|
57
60
|
* @returns List of prompts generated by the describer
|
|
58
61
|
*/
|
|
59
|
-
describe:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
describe:
|
|
63
|
+
| boolean
|
|
64
|
+
| null
|
|
65
|
+
| ((
|
|
66
|
+
ctx: MicroAgenticaContext<Model>,
|
|
67
|
+
executes: AgenticaExecuteHistory<Model>[],
|
|
68
|
+
) => Promise<MicroAgenticaHistory<Model>[]>);
|
|
63
69
|
}
|
|
@@ -175,7 +175,6 @@ function transformText(props: {
|
|
|
175
175
|
event: IAgenticaEventJson.IText;
|
|
176
176
|
}): AgenticaTextEvent {
|
|
177
177
|
return createTextEvent({
|
|
178
|
-
role: props.event.role,
|
|
179
178
|
stream: toAsyncGenerator(props.event.text),
|
|
180
179
|
done: () => true,
|
|
181
180
|
get: () => props.event.text,
|