@agentica/core 0.27.3 → 0.28.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 +17 -2
- package/lib/Agentica.d.ts +2 -1
- package/lib/Agentica.js +92 -60
- package/lib/Agentica.js.map +1 -1
- package/lib/MicroAgentica.d.ts +1 -0
- package/lib/MicroAgentica.js +88 -60
- package/lib/MicroAgentica.js.map +1 -1
- package/lib/constants/AgenticaDefaultPrompt.js +2 -18
- package/lib/constants/AgenticaDefaultPrompt.js.map +1 -1
- package/lib/context/AgenticaContext.d.ts +1 -1
- package/lib/context/MicroAgenticaContext.d.ts +2 -2
- package/lib/context/internal/AgenticaOperationComposer.spec.js +0 -2
- package/lib/context/internal/AgenticaOperationComposer.spec.js.map +1 -1
- package/lib/events/AgenticaEventBase.d.ts +9 -0
- package/lib/factory/events.d.ts +1 -2
- package/lib/factory/events.js +71 -7
- package/lib/factory/events.js.map +1 -1
- package/lib/factory/histories.js +27 -9
- package/lib/factory/histories.js.map +1 -1
- package/lib/histories/AgenticaCancelHistory.d.ts +1 -2
- package/lib/histories/AgenticaExecuteHistory.d.ts +0 -4
- package/lib/histories/AgenticaHistoryBase.d.ts +9 -0
- package/lib/histories/AgenticaSelectHistory.d.ts +1 -2
- package/lib/index.mjs +413 -380
- package/lib/index.mjs.map +1 -1
- package/lib/json/IAgenticaEventJson.d.ts +9 -1
- package/lib/json/IAgenticaHistoryJson.d.ts +11 -14
- package/lib/orchestrate/call.d.ts +2 -2
- package/lib/orchestrate/call.js +41 -70
- package/lib/orchestrate/call.js.map +1 -1
- package/lib/orchestrate/cancel.d.ts +1 -2
- package/lib/orchestrate/cancel.js +13 -38
- package/lib/orchestrate/cancel.js.map +1 -1
- package/lib/orchestrate/describe.d.ts +1 -2
- package/lib/orchestrate/describe.js +5 -17
- package/lib/orchestrate/describe.js.map +1 -1
- package/lib/orchestrate/execute.d.ts +1 -2
- package/lib/orchestrate/execute.js +9 -13
- package/lib/orchestrate/execute.js.map +1 -1
- package/lib/orchestrate/initialize.d.ts +1 -2
- package/lib/orchestrate/initialize.js +3 -11
- package/lib/orchestrate/initialize.js.map +1 -1
- package/lib/orchestrate/internal/{cancelFunction.js → cancelFunctionFromContext.js} +7 -7
- package/lib/orchestrate/internal/cancelFunctionFromContext.js.map +1 -0
- package/lib/orchestrate/internal/selectFunctionFromContext.js +24 -0
- package/lib/orchestrate/internal/selectFunctionFromContext.js.map +1 -0
- package/lib/orchestrate/select.d.ts +1 -2
- package/lib/orchestrate/select.js +20 -51
- package/lib/orchestrate/select.js.map +1 -1
- package/lib/structures/IAgenticaConfig.d.ts +1 -3
- package/lib/structures/IAgenticaExecutor.d.ts +6 -7
- package/lib/structures/IAgenticaVendor.d.ts +14 -0
- package/lib/structures/IMicroAgenticaExecutor.d.ts +2 -3
- package/lib/transformers/transformHistory.js +13 -8
- package/lib/transformers/transformHistory.js.map +1 -1
- package/lib/utils/ChatGptCompletionMessageUtil.js +3 -3
- package/package.json +9 -7
- package/src/Agentica.ts +127 -87
- package/src/MicroAgentica.ts +118 -81
- package/src/constants/AgenticaDefaultPrompt.ts +3 -20
- package/src/context/AgenticaContext.ts +1 -1
- package/src/context/MicroAgenticaContext.ts +2 -2
- package/src/context/internal/AgenticaOperationComposer.spec.ts +1 -2
- package/src/events/AgenticaEventBase.ts +12 -0
- package/src/factory/events.ts +78 -8
- package/src/factory/histories.ts +41 -11
- package/src/histories/AgenticaCancelHistory.ts +1 -2
- package/src/histories/AgenticaExecuteHistory.ts +0 -5
- package/src/histories/AgenticaHistoryBase.ts +12 -0
- package/src/histories/AgenticaSelectHistory.ts +1 -2
- package/src/json/IAgenticaEventJson.ts +11 -1
- package/src/json/IAgenticaHistoryJson.ts +14 -17
- package/src/orchestrate/call.ts +57 -107
- package/src/orchestrate/cancel.ts +76 -99
- package/src/orchestrate/describe.ts +16 -36
- package/src/orchestrate/execute.ts +17 -37
- package/src/orchestrate/initialize.ts +36 -49
- package/src/orchestrate/internal/{cancelFunction.ts → cancelFunctionFromContext.ts} +11 -11
- package/src/orchestrate/internal/{selectFunction.ts → selectFunctionFromContext.ts} +18 -13
- package/src/orchestrate/select.ts +112 -151
- package/src/structures/IAgenticaConfig.ts +1 -3
- package/src/structures/IAgenticaExecutor.ts +10 -8
- package/src/structures/IAgenticaVendor.ts +15 -0
- package/src/structures/IMicroAgenticaExecutor.ts +2 -3
- package/src/transformers/transformHistory.ts +19 -20
- package/lib/orchestrate/internal/cancelFunction.js.map +0 -1
- package/lib/orchestrate/internal/selectFunction.js +0 -35
- package/lib/orchestrate/internal/selectFunction.js.map +0 -1
- /package/lib/orchestrate/internal/{cancelFunction.d.ts → cancelFunctionFromContext.d.ts} +0 -0
- /package/lib/orchestrate/internal/{selectFunction.d.ts → selectFunctionFromContext.d.ts} +0 -0
|
@@ -3,27 +3,24 @@ import type OpenAI from "openai";
|
|
|
3
3
|
import type { IValidation } from "typia";
|
|
4
4
|
|
|
5
5
|
import typia from "typia";
|
|
6
|
-
import { v4 } from "uuid";
|
|
7
6
|
|
|
8
7
|
import type { AgenticaContext } from "../context/AgenticaContext";
|
|
9
8
|
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
10
9
|
import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
11
10
|
import type { __IChatFunctionReference } from "../context/internal/__IChatFunctionReference";
|
|
12
11
|
import type { __IChatSelectFunctionsApplication } from "../context/internal/__IChatSelectFunctionsApplication";
|
|
12
|
+
import type { AgenticaAssistantMessageEvent, AgenticaSelectEvent } from "../events";
|
|
13
13
|
import type { AgenticaEvent } from "../events/AgenticaEvent";
|
|
14
|
-
import type { AgenticaHistory } from "../histories/AgenticaHistory";
|
|
15
|
-
import type { AgenticaSelectHistory } from "../histories/AgenticaSelectHistory";
|
|
16
14
|
|
|
17
15
|
import { AgenticaConstant } from "../constants/AgenticaConstant";
|
|
18
16
|
import { AgenticaDefaultPrompt } from "../constants/AgenticaDefaultPrompt";
|
|
19
17
|
import { AgenticaSystemPrompt } from "../constants/AgenticaSystemPrompt";
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { createOperationSelection } from "../factory/operations";
|
|
18
|
+
import { creatAssistantMessageEvent } from "../factory/events";
|
|
19
|
+
import { decodeHistory, decodeUserMessageContent } from "../factory/histories";
|
|
23
20
|
import { ChatGptCompletionMessageUtil } from "../utils/ChatGptCompletionMessageUtil";
|
|
24
21
|
import { StreamUtil, toAsyncGenerator } from "../utils/StreamUtil";
|
|
25
22
|
|
|
26
|
-
import {
|
|
23
|
+
import { selectFunctionFromContext } from "./internal/selectFunctionFromContext";
|
|
27
24
|
|
|
28
25
|
const CONTAINER: ILlmApplication<"chatgpt"> = typia.llm.application<
|
|
29
26
|
__IChatSelectFunctionsApplication,
|
|
@@ -38,22 +35,23 @@ interface IFailure {
|
|
|
38
35
|
|
|
39
36
|
export async function select<Model extends ILlmSchema.Model>(
|
|
40
37
|
ctx: AgenticaContext<Model>,
|
|
41
|
-
): Promise<
|
|
38
|
+
): Promise<void> {
|
|
42
39
|
if (ctx.operations.divided === undefined) {
|
|
43
40
|
return step(ctx, ctx.operations.array, 0);
|
|
44
41
|
}
|
|
45
42
|
|
|
46
43
|
const stacks: AgenticaOperationSelection<Model>[][]
|
|
47
|
-
|
|
44
|
+
= ctx.operations.divided.map(() => []);
|
|
48
45
|
const events: AgenticaEvent<Model>[] = [];
|
|
49
|
-
|
|
46
|
+
await Promise.all(
|
|
50
47
|
ctx.operations.divided.map(async (operations, i) =>
|
|
51
48
|
step(
|
|
52
49
|
{
|
|
53
50
|
...ctx,
|
|
54
51
|
stack: stacks[i]!,
|
|
55
|
-
dispatch:
|
|
52
|
+
dispatch: (e) => {
|
|
56
53
|
events.push(e);
|
|
54
|
+
return e;
|
|
57
55
|
},
|
|
58
56
|
},
|
|
59
57
|
operations,
|
|
@@ -62,12 +60,11 @@ export async function select<Model extends ILlmSchema.Model>(
|
|
|
62
60
|
),
|
|
63
61
|
);
|
|
64
62
|
|
|
65
|
-
// NO FUNCTION SELECTION, SO THAT ONLY TEXT LEFT
|
|
66
|
-
if (stacks.every(s => s.length === 0)) {
|
|
67
|
-
return prompts[0]!;
|
|
68
|
-
}
|
|
69
63
|
// ELITICISM
|
|
70
|
-
|
|
64
|
+
if (
|
|
65
|
+
(ctx.config?.eliticism ?? AgenticaConstant.ELITICISM) === true
|
|
66
|
+
&& stacks.some(s => s.length !== 0)
|
|
67
|
+
) {
|
|
71
68
|
return step(
|
|
72
69
|
ctx,
|
|
73
70
|
stacks
|
|
@@ -81,22 +78,12 @@ export async function select<Model extends ILlmSchema.Model>(
|
|
|
81
78
|
0,
|
|
82
79
|
);
|
|
83
80
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
});
|
|
90
|
-
for (const e of events) {
|
|
91
|
-
if (e.type === "select") {
|
|
92
|
-
collection.selections.push(e.selection);
|
|
93
|
-
await selectFunction(ctx, {
|
|
94
|
-
name: e.selection.operation.name,
|
|
95
|
-
reason: e.selection.reason,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
81
|
+
else {
|
|
82
|
+
const selected: AgenticaSelectEvent<Model>[]
|
|
83
|
+
= events.filter(e => e.type === "select");
|
|
84
|
+
(selected.length !== 0 ? selected : events)
|
|
85
|
+
.forEach(ctx.dispatch);
|
|
98
86
|
}
|
|
99
|
-
return [collection];
|
|
100
87
|
}
|
|
101
88
|
|
|
102
89
|
async function step<Model extends ILlmSchema.Model>(
|
|
@@ -104,64 +91,64 @@ async function step<Model extends ILlmSchema.Model>(
|
|
|
104
91
|
operations: AgenticaOperation<Model>[],
|
|
105
92
|
retry: number,
|
|
106
93
|
failures?: IFailure[],
|
|
107
|
-
): Promise<
|
|
94
|
+
): Promise<void> {
|
|
108
95
|
// ----
|
|
109
96
|
// EXECUTE CHATGPT API
|
|
110
97
|
// ----
|
|
111
98
|
const completionStream = await ctx.request("select", {
|
|
112
99
|
messages: [
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
},
|
|
100
|
+
// COMMON SYSTEM PROMPT
|
|
101
|
+
{
|
|
102
|
+
role: "system",
|
|
103
|
+
content: AgenticaDefaultPrompt.write(ctx.config),
|
|
104
|
+
} satisfies OpenAI.ChatCompletionSystemMessageParam,
|
|
105
|
+
// CANDIDATE FUNCTIONS
|
|
106
|
+
{
|
|
107
|
+
role: "assistant",
|
|
108
|
+
tool_calls: [
|
|
109
|
+
{
|
|
110
|
+
type: "function",
|
|
111
|
+
id: "getApiFunctions",
|
|
112
|
+
function: {
|
|
113
|
+
name: "getApiFunctions",
|
|
114
|
+
arguments: JSON.stringify({}),
|
|
129
115
|
},
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
),
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
role: "tool",
|
|
121
|
+
tool_call_id: "getApiFunctions",
|
|
122
|
+
content: JSON.stringify(
|
|
123
|
+
operations.map(op => ({
|
|
124
|
+
name: op.name,
|
|
125
|
+
description: op.function.description,
|
|
126
|
+
...(op.protocol === "http"
|
|
127
|
+
? {
|
|
128
|
+
method: op.function.method,
|
|
129
|
+
path: op.function.path,
|
|
130
|
+
tags: op.function.tags,
|
|
131
|
+
}
|
|
132
|
+
: {}),
|
|
133
|
+
})),
|
|
134
|
+
),
|
|
135
|
+
},
|
|
136
|
+
// PREVIOUS HISTORIES
|
|
137
|
+
...ctx.histories.map(decodeHistory).flat(),
|
|
138
|
+
// USER INPUT
|
|
139
|
+
{
|
|
140
|
+
role: "user",
|
|
141
|
+
content: ctx.prompt.contents.map(decodeUserMessageContent),
|
|
142
|
+
},
|
|
143
|
+
// SYSTEM PROMPT
|
|
144
|
+
{
|
|
145
|
+
role: "system",
|
|
146
|
+
content:
|
|
147
|
+
ctx.config?.systemPrompt?.select?.(ctx.histories)
|
|
148
|
+
?? AgenticaSystemPrompt.SELECT,
|
|
149
|
+
},
|
|
150
|
+
// TYPE CORRECTIONS
|
|
151
|
+
...emendMessages(failures ?? []),
|
|
165
152
|
],
|
|
166
153
|
// STACK FUNCTIONS
|
|
167
154
|
tools: [{
|
|
@@ -189,6 +176,7 @@ async function step<Model extends ILlmSchema.Model>(
|
|
|
189
176
|
|
|
190
177
|
const chunks = await StreamUtil.readAll(completionStream);
|
|
191
178
|
const completion = ChatGptCompletionMessageUtil.merge(chunks);
|
|
179
|
+
|
|
192
180
|
// ----
|
|
193
181
|
// VALIDATION
|
|
194
182
|
// ----
|
|
@@ -199,9 +187,9 @@ async function step<Model extends ILlmSchema.Model>(
|
|
|
199
187
|
if (tc.function.name !== "selectFunctions") {
|
|
200
188
|
continue;
|
|
201
189
|
}
|
|
202
|
-
const input = JSON.parse(tc.function.arguments) as object;
|
|
190
|
+
const input: object = JSON.parse(tc.function.arguments) as object;
|
|
203
191
|
const validation: IValidation<__IChatFunctionReference.IProps>
|
|
204
|
-
|
|
192
|
+
= typia.validate<__IChatFunctionReference.IProps>(input);
|
|
205
193
|
if (validation.success === false) {
|
|
206
194
|
failures.push({
|
|
207
195
|
id: tc.id,
|
|
@@ -219,47 +207,26 @@ async function step<Model extends ILlmSchema.Model>(
|
|
|
219
207
|
// ----
|
|
220
208
|
// PROCESS COMPLETION
|
|
221
209
|
// ----
|
|
222
|
-
const prompts: AgenticaHistory<Model>[] = [];
|
|
223
210
|
for (const choice of completion.choices) {
|
|
224
|
-
//
|
|
211
|
+
// FUNCTION CALLING
|
|
225
212
|
if (choice.message.tool_calls != null) {
|
|
226
213
|
for (const tc of choice.message.tool_calls) {
|
|
227
214
|
if (tc.type !== "function") {
|
|
228
215
|
continue;
|
|
229
216
|
}
|
|
230
|
-
|
|
231
|
-
if (tc.function.name !== "selectFunctions") {
|
|
217
|
+
else if (tc.function.name !== "selectFunctions") {
|
|
232
218
|
continue;
|
|
233
219
|
}
|
|
234
|
-
const input = typia.json.isParse<__IChatFunctionReference.IProps>(tc.function.arguments);
|
|
235
220
|
|
|
221
|
+
const input: __IChatFunctionReference.IProps | null
|
|
222
|
+
= typia.json.isParse<__IChatFunctionReference.IProps>(
|
|
223
|
+
tc.function.arguments,
|
|
224
|
+
);
|
|
236
225
|
if (input === null) {
|
|
237
226
|
continue;
|
|
238
227
|
}
|
|
239
|
-
|
|
240
|
-
const collection: AgenticaSelectHistory<Model>
|
|
241
|
-
= createSelectHistory({
|
|
242
|
-
id: tc.id,
|
|
243
|
-
selections: [],
|
|
244
|
-
});
|
|
245
228
|
for (const reference of input.functions) {
|
|
246
|
-
|
|
247
|
-
= await selectFunction(ctx, reference);
|
|
248
|
-
|
|
249
|
-
if (operation === null) {
|
|
250
|
-
continue;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
collection.selections.push(
|
|
254
|
-
createOperationSelection({
|
|
255
|
-
operation,
|
|
256
|
-
reason: reference.reason,
|
|
257
|
-
}),
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
if (collection.selections.length !== 0) {
|
|
262
|
-
prompts.push(collection);
|
|
229
|
+
selectFunctionFromContext(ctx, reference);
|
|
263
230
|
}
|
|
264
231
|
}
|
|
265
232
|
}
|
|
@@ -270,52 +237,46 @@ async function step<Model extends ILlmSchema.Model>(
|
|
|
270
237
|
&& choice.message.content != null
|
|
271
238
|
&& choice.message.content.length !== 0
|
|
272
239
|
) {
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
done: () => true,
|
|
281
|
-
get: () => text.text,
|
|
282
|
-
}),
|
|
283
|
-
).catch(() => {});
|
|
240
|
+
const event: AgenticaAssistantMessageEvent = creatAssistantMessageEvent({
|
|
241
|
+
stream: toAsyncGenerator(choice.message.content),
|
|
242
|
+
join: async () => Promise.resolve(choice.message.content!),
|
|
243
|
+
done: () => true,
|
|
244
|
+
get: () => choice.message.content!,
|
|
245
|
+
});
|
|
246
|
+
ctx.dispatch(event);
|
|
284
247
|
}
|
|
285
248
|
}
|
|
286
|
-
|
|
287
|
-
return prompts;
|
|
288
249
|
}
|
|
289
250
|
|
|
290
251
|
function emendMessages(failures: IFailure[]): OpenAI.ChatCompletionMessageParam[] {
|
|
291
252
|
return failures
|
|
292
253
|
.map(f => [
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
},
|
|
254
|
+
{
|
|
255
|
+
role: "assistant",
|
|
256
|
+
tool_calls: [
|
|
257
|
+
{
|
|
258
|
+
type: "function",
|
|
259
|
+
id: f.id,
|
|
260
|
+
function: {
|
|
261
|
+
name: f.name,
|
|
262
|
+
arguments: JSON.stringify(f.validation.data),
|
|
303
263
|
},
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
264
|
+
},
|
|
265
|
+
],
|
|
266
|
+
} satisfies OpenAI.ChatCompletionAssistantMessageParam,
|
|
267
|
+
{
|
|
268
|
+
role: "tool",
|
|
269
|
+
content: JSON.stringify(f.validation.errors),
|
|
270
|
+
tool_call_id: f.id,
|
|
271
|
+
} satisfies OpenAI.ChatCompletionToolMessageParam,
|
|
272
|
+
{
|
|
273
|
+
role: "system",
|
|
274
|
+
content: [
|
|
275
|
+
"You A.I. assistant has composed wrong typed arguments.",
|
|
276
|
+
"",
|
|
277
|
+
"Correct it at the next function calling.",
|
|
278
|
+
].join("\n"),
|
|
279
|
+
} satisfies OpenAI.ChatCompletionSystemMessageParam,
|
|
319
280
|
])
|
|
320
281
|
.flat();
|
|
321
282
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
3
|
import type { AgenticaContext } from "../context/AgenticaContext";
|
|
4
|
-
import type { AgenticaHistory } from "../histories/AgenticaHistory";
|
|
5
4
|
|
|
6
5
|
import type { IAgenticaExecutor } from "./IAgenticaExecutor";
|
|
7
6
|
import type { IAgenticaSystemPrompt } from "./IAgenticaSystemPrompt";
|
|
@@ -36,12 +35,11 @@ export interface IAgenticaConfig<Model extends ILlmSchema.Model> {
|
|
|
36
35
|
* {@link ChatGptAgent.execute} function.
|
|
37
36
|
*
|
|
38
37
|
* @param ctx Context of the agent
|
|
39
|
-
* @returns Lit of prompts generated by the executor
|
|
40
38
|
* @default ChatGptAgent.execute
|
|
41
39
|
*/
|
|
42
40
|
executor?:
|
|
43
41
|
| Partial<IAgenticaExecutor<Model>>
|
|
44
|
-
| ((ctx: AgenticaContext<Model>) => Promise<
|
|
42
|
+
| ((ctx: AgenticaContext<Model>) => Promise<void>);
|
|
45
43
|
|
|
46
44
|
/**
|
|
47
45
|
* System prompt messages.
|
|
@@ -2,8 +2,7 @@ import type { ILlmSchema } from "@samchon/openapi";
|
|
|
2
2
|
|
|
3
3
|
import type { AgenticaContext } from "../context/AgenticaContext";
|
|
4
4
|
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
5
|
-
import type {
|
|
6
|
-
import type { AgenticaHistory } from "../histories/AgenticaHistory";
|
|
5
|
+
import type { AgenticaExecuteEvent } from "../events/AgenticaExecuteEvent";
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Executor of the Agentic AI.
|
|
@@ -61,7 +60,7 @@ export interface IAgenticaExecutor<Model extends ILlmSchema.Model> {
|
|
|
61
60
|
initialize:
|
|
62
61
|
| boolean
|
|
63
62
|
| null
|
|
64
|
-
| ((ctx: AgenticaContext<Model>) => Promise<
|
|
63
|
+
| ((ctx: AgenticaContext<Model>) => Promise<void>);
|
|
65
64
|
|
|
66
65
|
/**
|
|
67
66
|
* Function selector agent.
|
|
@@ -90,7 +89,7 @@ export interface IAgenticaExecutor<Model extends ILlmSchema.Model> {
|
|
|
90
89
|
* @param ctx Context of the agent
|
|
91
90
|
* @returns List of prompts generated by the selector
|
|
92
91
|
*/
|
|
93
|
-
select: (ctx: AgenticaContext<Model>) => Promise<
|
|
92
|
+
select: (ctx: AgenticaContext<Model>) => Promise<void>;
|
|
94
93
|
|
|
95
94
|
/**
|
|
96
95
|
* Function caller agent.
|
|
@@ -118,7 +117,10 @@ export interface IAgenticaExecutor<Model extends ILlmSchema.Model> {
|
|
|
118
117
|
* agent is the most general topic which can be universally
|
|
119
118
|
* applied to all domain fields.
|
|
120
119
|
*/
|
|
121
|
-
call: (
|
|
120
|
+
call: (
|
|
121
|
+
ctx: AgenticaContext<Model>,
|
|
122
|
+
operations: AgenticaOperation<Model>[],
|
|
123
|
+
) => Promise<AgenticaExecuteEvent<Model>[]>;
|
|
122
124
|
|
|
123
125
|
/**
|
|
124
126
|
* Describer agent of the function calling result.
|
|
@@ -138,8 +140,8 @@ export interface IAgenticaExecutor<Model extends ILlmSchema.Model> {
|
|
|
138
140
|
| null
|
|
139
141
|
| ((
|
|
140
142
|
ctx: AgenticaContext<Model>,
|
|
141
|
-
executes:
|
|
142
|
-
) => Promise<
|
|
143
|
+
executes: AgenticaExecuteEvent<Model>[],
|
|
144
|
+
) => Promise<void>);
|
|
143
145
|
|
|
144
146
|
/**
|
|
145
147
|
* Function canceler agent.
|
|
@@ -163,5 +165,5 @@ export interface IAgenticaExecutor<Model extends ILlmSchema.Model> {
|
|
|
163
165
|
* @param ctx Context of the agent
|
|
164
166
|
* @returns List of prompts generated by the canceler
|
|
165
167
|
*/
|
|
166
|
-
cancel: (ctx: AgenticaContext<Model>) => Promise<
|
|
168
|
+
cancel: (ctx: AgenticaContext<Model>) => Promise<void>;
|
|
167
169
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type OpenAI from "openai";
|
|
2
|
+
import type { Semaphore } from "tstl";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* LLM service vendor for Agentica Chat.
|
|
@@ -36,4 +37,18 @@ export interface IAgenticaVendor {
|
|
|
36
37
|
* Options for the request.
|
|
37
38
|
*/
|
|
38
39
|
options?: OpenAI.RequestOptions | undefined;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Number of concurrent requests allowed.
|
|
43
|
+
*
|
|
44
|
+
* If you configure this property, {@link Agentica} will constrain the
|
|
45
|
+
* number of concurrent requests to the LLM vendor. If you want to
|
|
46
|
+
* share the semaphore instance with other agents, you can directly
|
|
47
|
+
* assign the {@link Semaphore} instance to this property.
|
|
48
|
+
*
|
|
49
|
+
* Otherwise, it will not limit the number of concurrent
|
|
50
|
+
* requests, and the {@link Agentica} will send requests
|
|
51
|
+
* asynchronously without any limit.
|
|
52
|
+
*/
|
|
53
|
+
semaphore?: Semaphore | number | undefined;
|
|
39
54
|
}
|
|
@@ -2,7 +2,6 @@ import type { ILlmSchema } from "@samchon/openapi";
|
|
|
2
2
|
|
|
3
3
|
import type { MicroAgenticaContext } from "../context/MicroAgenticaContext";
|
|
4
4
|
import type { AgenticaExecuteHistory } from "../histories/AgenticaExecuteHistory";
|
|
5
|
-
import type { MicroAgenticaHistory } from "../histories/MicroAgenticaHistory";
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Executor of the Micro Agentic AI.
|
|
@@ -44,7 +43,7 @@ export interface IMicroAgenticaExecutor<Model extends ILlmSchema.Model> {
|
|
|
44
43
|
* agent is the most general topic which can be universally
|
|
45
44
|
* applied to all domain fields.
|
|
46
45
|
*/
|
|
47
|
-
call: (ctx: MicroAgenticaContext<Model>) => Promise<
|
|
46
|
+
call: (ctx: MicroAgenticaContext<Model>) => Promise<AgenticaExecuteHistory<Model>[]>;
|
|
48
47
|
|
|
49
48
|
/**
|
|
50
49
|
* Describer agent of the function calling result.
|
|
@@ -65,5 +64,5 @@ export interface IMicroAgenticaExecutor<Model extends ILlmSchema.Model> {
|
|
|
65
64
|
| ((
|
|
66
65
|
ctx: MicroAgenticaContext<Model>,
|
|
67
66
|
executes: AgenticaExecuteHistory<Model>[],
|
|
68
|
-
) => Promise<
|
|
67
|
+
) => Promise<void>);
|
|
69
68
|
}
|
|
@@ -89,16 +89,14 @@ function transformSelect<Model extends ILlmSchema.Model>(props: {
|
|
|
89
89
|
}): AgenticaSelectHistory<Model> {
|
|
90
90
|
return createSelectHistory({
|
|
91
91
|
id: props.history.id,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}),
|
|
101
|
-
),
|
|
92
|
+
created_at: props.history.created_at,
|
|
93
|
+
selection: createOperationSelection({
|
|
94
|
+
operation: findOperation({
|
|
95
|
+
operations: props.operations,
|
|
96
|
+
input: props.history.selection.operation,
|
|
97
|
+
}),
|
|
98
|
+
reason: props.history.selection.reason,
|
|
99
|
+
}),
|
|
102
100
|
});
|
|
103
101
|
}
|
|
104
102
|
|
|
@@ -108,16 +106,14 @@ function transformCancel<Model extends ILlmSchema.Model>(props: {
|
|
|
108
106
|
}): AgenticaCancelHistory<Model> {
|
|
109
107
|
return createCancelHistory({
|
|
110
108
|
id: props.history.id,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}),
|
|
120
|
-
),
|
|
109
|
+
created_at: props.history.created_at,
|
|
110
|
+
selection: createOperationSelection({
|
|
111
|
+
operation: findOperation({
|
|
112
|
+
operations: props.operations,
|
|
113
|
+
input: props.history.selection.operation,
|
|
114
|
+
}),
|
|
115
|
+
reason: props.history.selection.reason,
|
|
116
|
+
}),
|
|
121
117
|
});
|
|
122
118
|
}
|
|
123
119
|
|
|
@@ -127,6 +123,7 @@ function transformExecute<Model extends ILlmSchema.Model>(props: {
|
|
|
127
123
|
}): AgenticaExecuteHistory<Model> {
|
|
128
124
|
return createExecuteHistory({
|
|
129
125
|
id: props.history.id,
|
|
126
|
+
created_at: props.history.created_at,
|
|
130
127
|
operation: findOperation({
|
|
131
128
|
operations: props.operations,
|
|
132
129
|
input: props.history.operation,
|
|
@@ -145,6 +142,8 @@ function transformDescribe<Model extends ILlmSchema.Model>(props: {
|
|
|
145
142
|
history: IAgenticaHistoryJson.IDescribe;
|
|
146
143
|
}): AgenticaDescribeHistory<Model> {
|
|
147
144
|
return createDescribeHistory({
|
|
145
|
+
id: props.history.id,
|
|
146
|
+
created_at: props.history.created_at,
|
|
148
147
|
text: props.history.text,
|
|
149
148
|
executes: props.history.executes.map(next =>
|
|
150
149
|
transformExecute({
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cancelFunction.js","sourceRoot":"","sources":["../../../src/orchestrate/internal/cancelFunction.ts"],"names":[],"mappings":";;AAYA,wCAsBC;AA5BD,iDAAyD;AACzD,yDAAoE;AAEpE;;GAEG;AACH,SAAgB,cAAc,CAC5B,GAA2B,EAC3B,SAAmC;IAEnC,MAAM,KAAK,GAAW,GAAG,CAAC,KAAK,CAAC,SAAS,CACvC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,CAC/C,CAAC;IACF,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,IAAI,GAAsC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAE,CAAC;IAClE,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC3B,GAAG,CAAC,QAAQ,CACV,IAAA,0BAAiB,EAAC;QAChB,SAAS,EAAE,IAAA,qCAAwB,EAAC;YAClC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,MAAM,EAAE,SAAS,CAAC,MAAM;SACzB,CAAC;KACH,CAAC,CACH,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAClB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.selectFunction = selectFunction;
|
|
13
|
-
const events_1 = require("../../factory/events");
|
|
14
|
-
const operations_1 = require("../../factory/operations");
|
|
15
|
-
/**
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
|
-
function selectFunction(ctx, reference) {
|
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
const operation = ctx.operations.flat.get(reference.name);
|
|
21
|
-
if (operation === undefined) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
const selection = (0, operations_1.createOperationSelection)({
|
|
25
|
-
operation,
|
|
26
|
-
reason: reference.reason,
|
|
27
|
-
});
|
|
28
|
-
ctx.stack.push(selection);
|
|
29
|
-
ctx.dispatch((0, events_1.createSelectEvent)({
|
|
30
|
-
selection,
|
|
31
|
-
})).catch(() => { });
|
|
32
|
-
return operation;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=selectFunction.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selectFunction.js","sourceRoot":"","sources":["../../../src/orchestrate/internal/selectFunction.ts"],"names":[],"mappings":";;;;;;;;;;;AAaA,wCAmBC;AAzBD,iDAAyD;AACzD,yDAAoE;AAEpE;;GAEG;AACH,SAAsB,cAAc,CAAiC,GAA2B,EAAE,SAAmC;;QACnI,MAAM,SAAS,GACT,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,SAAS,GACT,IAAA,qCAAwB,EAAC;YACzB,SAAS;YACT,MAAM,EAAE,SAAS,CAAC,MAAM;SACzB,CAAC,CAAC;QACP,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC1B,GAAG,CAAC,QAAQ,CACV,IAAA,0BAAiB,EAAC;YAChB,SAAS;SACV,CAAC,CACH,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAClB,OAAO,SAAS,CAAC;IACnB,CAAC;CAAA"}
|
|
File without changes
|
|
File without changes
|