@agentica/core 0.12.21 → 0.13.1
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 +50 -47
- package/lib/Agentica.d.ts +9 -9
- package/lib/Agentica.js +23 -16
- package/lib/Agentica.js.map +1 -1
- package/lib/chatgpt/ChatGptAgent.d.ts +7 -7
- package/lib/chatgpt/ChatGptAgent.js +17 -12
- package/lib/chatgpt/ChatGptAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCallFunctionAgent.d.ts +7 -6
- package/lib/chatgpt/ChatGptCallFunctionAgent.js +120 -81
- package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCancelFunctionAgent.d.ts +9 -7
- package/lib/chatgpt/ChatGptCancelFunctionAgent.js +177 -145
- package/lib/chatgpt/ChatGptCancelFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCompletionMessageUtil.d.ts +13 -8
- package/lib/chatgpt/ChatGptCompletionMessageUtil.js +499 -489
- package/lib/chatgpt/ChatGptCompletionMessageUtil.js.map +1 -1
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.d.ts +7 -6
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.js +33 -32
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptHistoryDecoder.d.ts +7 -6
- package/lib/chatgpt/ChatGptHistoryDecoder.js +60 -56
- package/lib/chatgpt/ChatGptHistoryDecoder.js.map +1 -1
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.d.ts +7 -6
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.js +121 -116
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptSelectFunctionAgent.d.ts +20 -5
- package/lib/chatgpt/ChatGptSelectFunctionAgent.js +183 -150
- package/lib/chatgpt/ChatGptSelectFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptUsageAggregator.d.ts +9 -6
- package/lib/chatgpt/ChatGptUsageAggregator.js +46 -41
- package/lib/chatgpt/ChatGptUsageAggregator.js.map +1 -1
- package/lib/context/AgenticaCancelPrompt.d.ts +3 -3
- package/lib/context/AgenticaCancelPrompt.js +1 -1
- package/lib/context/AgenticaCancelPrompt.js.map +1 -1
- package/lib/context/AgenticaClassOperation.d.ts +1 -1
- package/lib/context/AgenticaClassOperation.js.map +1 -1
- package/lib/context/AgenticaContext.d.ts +9 -9
- package/lib/context/AgenticaHttpOperation.d.ts +1 -1
- package/lib/context/AgenticaHttpOperation.js.map +1 -1
- package/lib/context/AgenticaOperation.d.ts +4 -4
- package/lib/context/AgenticaOperationBase.d.ts +1 -1
- package/lib/context/AgenticaOperationCollection.d.ts +2 -2
- package/lib/context/AgenticaOperationSelection.d.ts +3 -3
- package/lib/context/AgenticaTokenUsage.d.ts +1 -1
- package/lib/context/AgenticaTokenUsage.js.map +1 -1
- package/lib/context/internal/AgenticaTokenUsageAggregator.d.ts +11 -10
- package/lib/context/internal/AgenticaTokenUsageAggregator.js +42 -43
- package/lib/context/internal/AgenticaTokenUsageAggregator.js.map +1 -1
- package/lib/context/internal/__IChatCancelFunctionsApplication.d.ts +2 -2
- package/lib/context/internal/__IChatInitialApplication.d.ts +2 -2
- package/lib/context/internal/__IChatSelectFunctionsApplication.d.ts +2 -2
- package/lib/events/AgenticaCallEvent.d.ts +3 -3
- package/lib/events/AgenticaCancelEvent.d.ts +3 -3
- package/lib/events/AgenticaDescribeEvent.d.ts +3 -3
- package/lib/events/AgenticaDescribeEvent.js +13 -2
- package/lib/events/AgenticaDescribeEvent.js.map +1 -1
- package/lib/events/AgenticaEvent.d.ts +12 -12
- package/lib/events/AgenticaExecuteEvent.d.ts +7 -7
- package/lib/events/AgenticaInitializeEvent.d.ts +1 -1
- package/lib/events/AgenticaRequestEvent.d.ts +3 -3
- package/lib/events/AgenticaRequestEvent.js.map +1 -1
- package/lib/events/AgenticaResponseEvent.d.ts +2 -2
- package/lib/events/AgenticaResponseEvent.js.map +1 -1
- package/lib/events/AgenticaSelectEvent.d.ts +3 -3
- package/lib/events/AgenticaSelectEvent.js.map +1 -1
- package/lib/events/AgenticaTextEvent.d.ts +1 -1
- package/lib/events/AgenticaTextEvent.js +12 -1
- package/lib/events/AgenticaTextEvent.js.map +1 -1
- package/lib/functional/assertHttpLlmApplication.d.ts +4 -3
- package/lib/functional/assertHttpLlmApplication.js +9339 -9338
- package/lib/functional/assertHttpLlmApplication.js.map +1 -1
- package/lib/functional/validateHttpLlmApplication.d.ts +5 -4
- package/lib/functional/validateHttpLlmApplication.js +19 -19
- package/lib/functional/validateHttpLlmApplication.js.map +1 -1
- package/lib/index.d.ts +19 -19
- package/lib/index.js +21 -21
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +19210 -18997
- package/lib/index.mjs.map +1 -1
- package/lib/internal/AgenticaDefaultPrompt.d.ts +6 -5
- package/lib/internal/AgenticaDefaultPrompt.js +39 -19
- package/lib/internal/AgenticaDefaultPrompt.js.map +1 -1
- package/lib/internal/AgenticaOperationComposer.d.ts +11 -10
- package/lib/internal/AgenticaOperationComposer.js +60 -59
- package/lib/internal/AgenticaOperationComposer.js.map +1 -1
- package/lib/internal/AgenticaSystemPrompt.d.ts +8 -8
- package/lib/internal/AgenticaSystemPrompt.js +9 -9
- package/lib/internal/AgenticaSystemPrompt.js.map +1 -1
- package/lib/internal/AsyncQueue.d.ts +15 -0
- package/lib/internal/AsyncQueue.js +82 -0
- package/lib/internal/AsyncQueue.js.map +1 -0
- package/lib/internal/ByteArrayUtil.d.ts +1 -1
- package/lib/internal/ByteArrayUtil.js +3 -2
- package/lib/internal/ByteArrayUtil.js.map +1 -1
- package/lib/internal/MPSC.d.ts +10 -0
- package/lib/internal/MPSC.js +49 -0
- package/lib/internal/MPSC.js.map +1 -0
- package/lib/internal/Singleton.js +6 -5
- package/lib/internal/Singleton.js.map +1 -1
- package/lib/internal/StreamUtil.d.ts +16 -6
- package/lib/internal/StreamUtil.js +43 -29
- package/lib/internal/StreamUtil.js.map +1 -1
- package/lib/internal/__map_take.js +5 -5
- package/lib/internal/__map_take.js.map +1 -1
- package/lib/json/IAgenticaEventJson.d.ts +7 -7
- package/lib/json/IAgenticaOperationSelectionJson.d.ts +1 -1
- package/lib/json/IAgenticaPromptJson.d.ts +2 -2
- package/lib/prompts/AgenticaCancelPrompt.d.ts +3 -3
- package/lib/prompts/AgenticaCancelPrompt.js +1 -1
- package/lib/prompts/AgenticaCancelPrompt.js.map +1 -1
- package/lib/prompts/AgenticaDescribePrompt.d.ts +3 -3
- package/lib/prompts/AgenticaDescribePrompt.js +1 -1
- package/lib/prompts/AgenticaDescribePrompt.js.map +1 -1
- package/lib/prompts/AgenticaExecutePrompt.d.ts +5 -5
- package/lib/prompts/AgenticaExecutePrompt.js.map +1 -1
- package/lib/prompts/AgenticaPrompt.d.ts +6 -6
- package/lib/prompts/AgenticaSelectPrompt.d.ts +3 -3
- package/lib/prompts/AgenticaSelectPrompt.js +1 -1
- package/lib/prompts/AgenticaSelectPrompt.js.map +1 -1
- package/lib/prompts/AgenticaTextPrompt.d.ts +1 -1
- package/lib/structures/IAgenticaConfig.d.ts +5 -5
- package/lib/structures/IAgenticaController.d.ts +1 -1
- package/lib/structures/IAgenticaExecutor.d.ts +4 -4
- package/lib/structures/IAgenticaProps.d.ts +5 -5
- package/lib/structures/IAgenticaSystemPrompt.d.ts +4 -4
- package/lib/structures/IAgenticaVendor.d.ts +1 -1
- package/lib/transformers/AgenticaEventTransformer.d.ts +55 -37
- package/lib/transformers/AgenticaEventTransformer.js +105 -58
- package/lib/transformers/AgenticaEventTransformer.js.map +1 -1
- package/lib/transformers/AgenticaPromptTransformer.d.ts +35 -29
- package/lib/transformers/AgenticaPromptTransformer.js +74 -45
- package/lib/transformers/AgenticaPromptTransformer.js.map +1 -1
- package/package.json +20 -23
- package/prompts/cancel.md +1 -1
- package/prompts/common.md +1 -1
- package/prompts/describe.md +1 -1
- package/prompts/execute.md +1 -1
- package/prompts/initialize.md +1 -1
- package/prompts/select.md +1 -1
- package/src/Agentica.ts +41 -31
- package/src/chatgpt/ChatGptAgent.ts +63 -57
- package/src/chatgpt/ChatGptCallFunctionAgent.ts +361 -337
- package/src/chatgpt/ChatGptCancelFunctionAgent.ts +188 -164
- package/src/chatgpt/ChatGptCompletionMessageUtil.ts +136 -137
- package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +105 -101
- package/src/chatgpt/ChatGptHistoryDecoder.ts +69 -65
- package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +128 -123
- package/src/chatgpt/ChatGptSelectFunctionAgent.ts +215 -189
- package/src/chatgpt/ChatGptUsageAggregator.ts +49 -54
- package/src/context/AgenticaCancelPrompt.ts +4 -4
- package/src/context/AgenticaClassOperation.ts +5 -5
- package/src/context/AgenticaContext.ts +15 -15
- package/src/context/AgenticaHttpOperation.ts +5 -5
- package/src/context/AgenticaOperation.ts +4 -4
- package/src/context/AgenticaOperationBase.ts +1 -1
- package/src/context/AgenticaOperationCollection.ts +2 -2
- package/src/context/AgenticaOperationSelection.ts +3 -3
- package/src/context/AgenticaTokenUsage.ts +4 -3
- package/src/context/internal/AgenticaTokenUsageAggregator.ts +59 -59
- package/src/context/internal/__IChatCancelFunctionsApplication.ts +2 -2
- package/src/context/internal/__IChatInitialApplication.ts +2 -2
- package/src/context/internal/__IChatSelectFunctionsApplication.ts +2 -2
- package/src/events/AgenticaCallEvent.ts +3 -3
- package/src/events/AgenticaCancelEvent.ts +3 -3
- package/src/events/AgenticaDescribeEvent.ts +5 -5
- package/src/events/AgenticaEvent.ts +12 -12
- package/src/events/AgenticaExecuteEvent.ts +7 -7
- package/src/events/AgenticaInitializeEvent.ts +1 -1
- package/src/events/AgenticaRequestEvent.ts +3 -3
- package/src/events/AgenticaResponseEvent.ts +2 -2
- package/src/events/AgenticaSelectEvent.ts +4 -4
- package/src/events/AgenticaTextEvent.ts +2 -2
- package/src/functional/assertHttpLlmApplication.ts +9 -6
- package/src/functional/validateHttpLlmApplication.ts +14 -8
- package/src/index.ts +24 -24
- package/src/internal/AgenticaDefaultPrompt.ts +42 -28
- package/src/internal/AgenticaOperationComposer.ts +63 -61
- package/src/internal/AgenticaSystemPrompt.ts +15 -14
- package/src/internal/AsyncQueue.ts +67 -0
- package/src/internal/ByteArrayUtil.ts +2 -2
- package/src/internal/MPSC.ts +40 -0
- package/src/internal/Singleton.ts +8 -6
- package/src/internal/StreamUtil.ts +62 -53
- package/src/internal/__map_take.ts +5 -7
- package/src/json/IAgenticaEventJson.ts +7 -8
- package/src/json/IAgenticaOperationSelectionJson.ts +1 -1
- package/src/json/IAgenticaPromptJson.ts +2 -2
- package/src/prompts/AgenticaCancelPrompt.ts +4 -4
- package/src/prompts/AgenticaDescribePrompt.ts +4 -4
- package/src/prompts/AgenticaExecutePrompt.ts +6 -5
- package/src/prompts/AgenticaPrompt.ts +6 -6
- package/src/prompts/AgenticaSelectPrompt.ts +4 -4
- package/src/prompts/AgenticaTextPrompt.ts +1 -1
- package/src/structures/IAgenticaConfig.ts +5 -5
- package/src/structures/IAgenticaController.ts +14 -14
- package/src/structures/IAgenticaExecutor.ts +4 -4
- package/src/structures/IAgenticaProps.ts +5 -5
- package/src/structures/IAgenticaSystemPrompt.ts +4 -4
- package/src/structures/IAgenticaVendor.ts +1 -1
- package/src/transformers/AgenticaEventTransformer.ts +169 -136
- package/src/transformers/AgenticaPromptTransformer.ts +125 -103
- package/lib/internal/MPSCUtil.d.ts +0 -35
- package/lib/internal/MPSCUtil.js +0 -105
- package/lib/internal/MPSCUtil.js.map +0 -1
- package/src/internal/MPSCUtil.ts +0 -111
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# `@agentica/core`
|
|
2
|
+
|
|
2
3
|

|
|
3
4
|
|
|
4
5
|
[](https://github.com/wrtnlabs/agentica/blob/master/LICENSE)
|
|
@@ -33,11 +34,10 @@ await agent.conversate("I wanna buy MacBook Pro");
|
|
|
33
34
|
>
|
|
34
35
|
> Demonstration video of Shopping AI Chatbot
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
37
|
## How to Use
|
|
38
|
+
|
|
40
39
|
### Setup
|
|
40
|
+
|
|
41
41
|
```bash
|
|
42
42
|
npm install @agentica/core @samchon/openapi typia
|
|
43
43
|
npx typia setup
|
|
@@ -50,19 +50,20 @@ Install not only `@agentica/core`, but also [`@samchon/openapi`](https://github.
|
|
|
50
50
|
By the way, as `typia` is a transformer library analyzing TypeScript source code in the compilation level, it needs additional setup command `npx typia setup`. Also, if you're not using non-standard TypeScript compiler (not `tsc`) or developing the agent in the frontend environment, you have to setup [`@ryoppippi/unplugin-typia`](https://typia.io/docs/setup/#unplugin-typia) too.
|
|
51
51
|
|
|
52
52
|
### Chat with Backend Server
|
|
53
|
+
|
|
53
54
|
```typescript
|
|
54
|
-
import { IHttpLlmApplication } from "@samchon/openapi";
|
|
55
55
|
import { Agentica, validateHttpLlmApplication } from "@agentica/core";
|
|
56
|
+
import { IHttpLlmApplication } from "@samchon/openapi";
|
|
56
57
|
import OpenAI from "openai";
|
|
57
58
|
import { IValidation } from "typia";
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
async function main(): Promise<void> {
|
|
60
61
|
// LOAD SWAGGER DOCUMENT, AND CONVERT TO LLM APPLICATION SCHEMA
|
|
61
|
-
const application: IValidation<IHttpLlmApplication<"chatgpt">>
|
|
62
|
-
validateHttpLlmApplication({
|
|
62
|
+
const application: IValidation<IHttpLlmApplication<"chatgpt">>
|
|
63
|
+
= validateHttpLlmApplication({
|
|
63
64
|
model: "chatgpt",
|
|
64
65
|
document: await fetch("https://shopping-be.wrtn.ai/editor/swagger.json").then(
|
|
65
|
-
|
|
66
|
+
r => r.json()
|
|
66
67
|
),
|
|
67
68
|
});
|
|
68
69
|
if (application.success === false) {
|
|
@@ -108,7 +109,7 @@ const main = async (): Promise<void> => {
|
|
|
108
109
|
|
|
109
110
|
// CONVERSATE TO AI CHATBOT
|
|
110
111
|
await agent.conversate("What you can do?");
|
|
111
|
-
}
|
|
112
|
+
}
|
|
112
113
|
main().catch(console.error);
|
|
113
114
|
```
|
|
114
115
|
|
|
@@ -119,10 +120,11 @@ Then you can start conversation with your backend server, and the API functions
|
|
|
119
120
|
From now on, every backend developer is also an AI developer.
|
|
120
121
|
|
|
121
122
|
### Chat with TypeScript Class
|
|
123
|
+
|
|
122
124
|
```typescript
|
|
123
125
|
import { Agentica } from "@agentica/core";
|
|
124
|
-
import typia, { tags } from "typia";
|
|
125
126
|
import OpenAI from "openai";
|
|
127
|
+
import typia, { tags } from "typia";
|
|
126
128
|
|
|
127
129
|
class BbsArticleService {
|
|
128
130
|
/**
|
|
@@ -161,7 +163,7 @@ class BbsArticleService {
|
|
|
161
163
|
}): Promise<void>;
|
|
162
164
|
}
|
|
163
165
|
|
|
164
|
-
|
|
166
|
+
async function main(): Promise<void> {
|
|
165
167
|
const api: OpenAI = new OpenAI({
|
|
166
168
|
apiKey: "YOUR_OPENAI_API_KEY",
|
|
167
169
|
});
|
|
@@ -186,7 +188,7 @@ const main = async (): Promise<void> => {
|
|
|
186
188
|
],
|
|
187
189
|
});
|
|
188
190
|
await agent.conversate("I wanna write an article.");
|
|
189
|
-
}
|
|
191
|
+
}
|
|
190
192
|
main().catch(console.error);
|
|
191
193
|
```
|
|
192
194
|
|
|
@@ -197,10 +199,11 @@ Just deliver the TypeScript type to the `@agentica/core`, and start conversation
|
|
|
197
199
|
From now on, every TypeScript classes you've developed can be the AI chatbot.
|
|
198
200
|
|
|
199
201
|
### Multi Agent Orchestration
|
|
202
|
+
|
|
200
203
|
```typescript
|
|
201
204
|
import { Agentica } from "@agentica/core";
|
|
202
|
-
import typia from "typia";
|
|
203
205
|
import OpenAI from "openai";
|
|
206
|
+
import typia from "typia";
|
|
204
207
|
|
|
205
208
|
class OpenAIVectorStoreAgent {
|
|
206
209
|
/**
|
|
@@ -220,7 +223,7 @@ class OpenAIVectorStoreAgent {
|
|
|
220
223
|
}): Promise<IVectorStoreQueryResult>;
|
|
221
224
|
}
|
|
222
225
|
|
|
223
|
-
|
|
226
|
+
async function main(): Promise<void> {
|
|
224
227
|
const api: OpenAI = new OpenAI({
|
|
225
228
|
apiKey: "YOUR_OPENAI_API_KEY",
|
|
226
229
|
});
|
|
@@ -248,7 +251,7 @@ const main = async (): Promise<void> => {
|
|
|
248
251
|
],
|
|
249
252
|
});
|
|
250
253
|
await agent.conversate("I wanna research economic articles");
|
|
251
|
-
}
|
|
254
|
+
}
|
|
252
255
|
main().catch(console.error);
|
|
253
256
|
```
|
|
254
257
|
|
|
@@ -256,13 +259,12 @@ In the `@agentica/core`, you can implement multi-agent orchestration super easil
|
|
|
256
259
|
|
|
257
260
|
Just develop a TypeScript class which contains agent feature like Vector Store, and just deliver the TypeScript class type to the `@agentica/core` like above. The `@agentica/core` will centralize and realize the multi-agent orchestration by LLM function calling strategy to the TypeScript class.
|
|
258
261
|
|
|
259
|
-
|
|
260
262
|
### If you want drastically improves function selection speed
|
|
261
263
|
|
|
262
264
|
Use the [@agentica/pg-vector-selector](../pg-vector-selector/README.md)
|
|
263
265
|
|
|
264
|
-
Just initialize and set the config
|
|
265
|
-
when use this adapter, you should run the [connector-hive](https://github.com/wrtnlabs/connector-hive)
|
|
266
|
+
Just initialize and set the config
|
|
267
|
+
when use this adapter, you should run the [connector-hive](https://github.com/wrtnlabs/connector-hive)
|
|
266
268
|
|
|
267
269
|
```typescript
|
|
268
270
|
import { Agentica } from "@agentica/core";
|
|
@@ -270,13 +272,11 @@ import { AgenticaPgVectorSelector } from "@agentica/pg-vector-selector";
|
|
|
270
272
|
|
|
271
273
|
import typia from "typia";
|
|
272
274
|
|
|
273
|
-
|
|
274
275
|
// Initialize with connector-hive server
|
|
275
276
|
const selectorExecute = AgenticaPgVectorSelector.boot<"chatgpt">(
|
|
276
|
-
|
|
277
|
+
"https://your-connector-hive-server.com"
|
|
277
278
|
);
|
|
278
279
|
|
|
279
|
-
|
|
280
280
|
const agent = new Agentica({
|
|
281
281
|
model: "chatgpt",
|
|
282
282
|
vendor: {
|
|
@@ -302,9 +302,10 @@ const agent = new Agentica({
|
|
|
302
302
|
await agent.conversate("I wanna buy MacBook Pro");
|
|
303
303
|
```
|
|
304
304
|
|
|
305
|
-
|
|
306
305
|
## Principles
|
|
306
|
+
|
|
307
307
|
### Agent Strategy
|
|
308
|
+
|
|
308
309
|
```mermaid
|
|
309
310
|
sequenceDiagram
|
|
310
311
|
actor User
|
|
@@ -360,18 +361,19 @@ And `@agentica/core` enters to a loop statement until the candidate functions to
|
|
|
360
361
|
Such LLM (Large Language Model) function calling strategy separating `selector`, `caller`, and `describer` is the key logic of `@agentica/core`.
|
|
361
362
|
|
|
362
363
|
### Validation Feedback
|
|
364
|
+
|
|
363
365
|
```typescript
|
|
364
366
|
import { FunctionCall } from "pseudo";
|
|
365
367
|
import { ILlmFunction, IValidation } from "typia";
|
|
366
368
|
|
|
367
|
-
export
|
|
369
|
+
export function correctFunctionCall(p: {
|
|
368
370
|
call: FunctionCall;
|
|
369
371
|
functions: Array<ILlmFunction<"chatgpt">>;
|
|
370
372
|
retry: (reason: string, errors?: IValidation.IError[]) => Promise<unknown>;
|
|
371
|
-
}): Promise<unknown>
|
|
373
|
+
}): Promise<unknown> {
|
|
372
374
|
// FIND FUNCTION
|
|
373
|
-
const func: ILlmFunction<"chatgpt"> | undefined
|
|
374
|
-
p.functions.find(
|
|
375
|
+
const func: ILlmFunction<"chatgpt"> | undefined
|
|
376
|
+
= p.functions.find(f => f.name === p.call.name);
|
|
375
377
|
if (func === undefined) {
|
|
376
378
|
// never happened in my experience
|
|
377
379
|
return p.retry(
|
|
@@ -396,7 +398,7 @@ export const correctFunctionCall = (p: {
|
|
|
396
398
|
}
|
|
397
399
|
```
|
|
398
400
|
|
|
399
|
-
Is LLM function calling perfect?
|
|
401
|
+
Is LLM function calling perfect?
|
|
400
402
|
|
|
401
403
|
The answer is not, and LLM (Large Language Model) vendors like OpenAI take a lot of type level mistakes when composing the arguments of the target function to call. Even though an LLM function calling schema has defined an `Array<string>` type, LLM often fills it just by a `string` typed value.
|
|
402
404
|
|
|
@@ -406,29 +408,30 @@ About the validation feedback, `@agentica/core` is utilizing [`typia.validate<T>
|
|
|
406
408
|
|
|
407
409
|
Such validation feedback strategy and combination with `typia` runtime validator, `@agentica/core` has achieved the most ideal LLM function calling. In my experience, when using OpenAI's `gpt-4o-mini` model, it tends to construct invalid function calling arguments at the first trial about 50% of the time. By the way, if correct it through validation feedback with `typia`, success rate soars to 99%. And I've never had a failure when trying validation feedback twice.
|
|
408
410
|
|
|
409
|
-
Components
|
|
410
|
-
|
|
411
|
-
**Easy to use**
|
|
412
|
-
[Object (simple)](https://github.com/samchon/typia/blob/master/test/src/structures/ObjectSimple.ts)
|
|
413
|
-
[Object (hierarchical)](https://github.com/samchon/typia/blob/master/test/src/structures/ObjectHierarchical.ts)
|
|
414
|
-
[Object (recursive)](https://github.com/samchon/typia/blob/master/test/src/structures/ObjectRecursive.ts)
|
|
415
|
-
[Object (union, implicit)](https://github.com/samchon/typia/blob/master/test/src/structures/ObjectUnionImplicit.ts)
|
|
416
|
-
[Object (union, explicit)](https://github.com/samchon/typia/blob/master/test/src/structures/ObjectUnionExplicit.ts)
|
|
417
|
-
[Object (additional tags)](https://github.com/samchon/typia/#comment-tags)
|
|
418
|
-
[Object (template literal types)](https://github.com/samchon/typia/blob/master/test/src/structures/TemplateUnion.ts)
|
|
419
|
-
[Object (dynamic properties)](https://github.com/samchon/typia/blob/master/test/src/structures/DynamicTemplate.ts)
|
|
420
|
-
[Array (rest tuple)](https://github.com/samchon/typia/blob/master/test/src/structures/TupleRestAtomic.ts)
|
|
421
|
-
[Array (hierarchical)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayHierarchical.ts)
|
|
422
|
-
[Array (recursive)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayRecursive.ts)
|
|
423
|
-
[Array (recursive, union)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayRecursiveUnionExplicit.ts) | ✔
|
|
424
|
-
[Array (R+U, implicit)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayRecursiveUnionImplicit.ts) | ✅
|
|
425
|
-
[Array (repeated)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayRepeatedNullable.ts)
|
|
426
|
-
[Array (repeated, union)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayRepeatedUnionWithTuple.ts)
|
|
427
|
-
[**Ultimate Union Type**](https://github.com/samchon/typia/blob/master/test/src/structures/UltimateUnion.ts)
|
|
411
|
+
| Components | `typia` | `TypeBox` | `ajv` | `io-ts` | `zod` | `C.V.` |
|
|
412
|
+
| --------------------------------------------------------------------------------------------------------------------------- | ------- | --------- | ----- | ------- | ----- | ------ | --- |
|
|
413
|
+
| **Easy to use** | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
|
414
|
+
| [Object (simple)](https://github.com/samchon/typia/blob/master/test/src/structures/ObjectSimple.ts) | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
|
|
415
|
+
| [Object (hierarchical)](https://github.com/samchon/typia/blob/master/test/src/structures/ObjectHierarchical.ts) | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
|
|
416
|
+
| [Object (recursive)](https://github.com/samchon/typia/blob/master/test/src/structures/ObjectRecursive.ts) | ✔ | ❌ | ✔ | ✔ | ✔ | ✔ | ✔ |
|
|
417
|
+
| [Object (union, implicit)](https://github.com/samchon/typia/blob/master/test/src/structures/ObjectUnionImplicit.ts) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
|
418
|
+
| [Object (union, explicit)](https://github.com/samchon/typia/blob/master/test/src/structures/ObjectUnionExplicit.ts) | ✔ | ✔ | ✔ | ✔ | ✔ | ❌ |
|
|
419
|
+
| [Object (additional tags)](https://github.com/samchon/typia/#comment-tags) | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
|
|
420
|
+
| [Object (template literal types)](https://github.com/samchon/typia/blob/master/test/src/structures/TemplateUnion.ts) | ✔ | ✔ | ✔ | ❌ | ❌ | ❌ |
|
|
421
|
+
| [Object (dynamic properties)](https://github.com/samchon/typia/blob/master/test/src/structures/DynamicTemplate.ts) | ✔ | ✔ | ✔ | ❌ | ❌ | ❌ |
|
|
422
|
+
| [Array (rest tuple)](https://github.com/samchon/typia/blob/master/test/src/structures/TupleRestAtomic.ts) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
|
423
|
+
| [Array (hierarchical)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayHierarchical.ts) | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
|
|
424
|
+
| [Array (recursive)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayRecursive.ts) | ✔ | ✔ | ✔ | ✔ | ✔ | ❌ |
|
|
425
|
+
| [Array (recursive, union)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayRecursiveUnionExplicit.ts) | ✔ | ✔ | ❌ | ✔ | ✔ | ❌ |
|
|
426
|
+
| [Array (R+U, implicit)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayRecursiveUnionImplicit.ts) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
|
427
|
+
| [Array (repeated)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayRepeatedNullable.ts) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
|
428
|
+
| [Array (repeated, union)](https://github.com/samchon/typia/blob/master/test/src/structures/ArrayRepeatedUnionWithTuple.ts) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
|
429
|
+
| [**Ultimate Union Type**](https://github.com/samchon/typia/blob/master/test/src/structures/UltimateUnion.ts) | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
|
428
430
|
|
|
429
431
|
> `C.V.` means `class-validator`
|
|
430
432
|
|
|
431
433
|
### OpenAPI Specification
|
|
434
|
+
|
|
432
435
|
```mermaid
|
|
433
436
|
flowchart
|
|
434
437
|
subgraph "OpenAPI Specification"
|
|
@@ -448,7 +451,7 @@ flowchart
|
|
|
448
451
|
|
|
449
452
|
`@agentica/core` obtains LLM function calling schemas from both Swagger/OpenAPI documents and TypeScript class types. The TypeScript class type can be converted to LLM function calling schema by [`typia.llm.application<Class, Model>()`](https://typia.io/docs/llm/application#application) function. Then how about OpenAPI document? How Swagger document can be LLM function calling schema.
|
|
450
453
|
|
|
451
|
-
The secret is on the above diagram.
|
|
454
|
+
The secret is on the above diagram.
|
|
452
455
|
|
|
453
456
|
In the OpenAPI specification, there are three versions with different definitions. And even in the same version, there are too much ambiguous and duplicated expressions. To resolve these problems, [`@samchon/openapi`](https://github.com/samchon/openapi) is transforming every OpenAPI documents to v3.1 emended specification. The `@samchon/openapi`'s emended v3.1 specification has removed every ambiguous and duplicated expressions for clarity.
|
|
454
457
|
|
package/lib/Agentica.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import { AgenticaOperation } from "./context/AgenticaOperation";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import type { AgenticaOperation } from "./context/AgenticaOperation";
|
|
3
|
+
import type { AgenticaEvent } from "./events/AgenticaEvent";
|
|
4
|
+
import type { AgenticaPrompt } from "./prompts/AgenticaPrompt";
|
|
5
|
+
import type { IAgenticaConfig } from "./structures/IAgenticaConfig";
|
|
6
|
+
import type { IAgenticaController } from "./structures/IAgenticaController";
|
|
7
|
+
import type { IAgenticaProps } from "./structures/IAgenticaProps";
|
|
8
|
+
import type { IAgenticaVendor } from "./structures/IAgenticaVendor";
|
|
3
9
|
import { AgenticaTokenUsage } from "./context/AgenticaTokenUsage";
|
|
4
|
-
import { AgenticaEvent } from "./events/AgenticaEvent";
|
|
5
|
-
import { AgenticaPrompt } from "./prompts/AgenticaPrompt";
|
|
6
|
-
import { IAgenticaConfig } from "./structures/IAgenticaConfig";
|
|
7
|
-
import { IAgenticaController } from "./structures/IAgenticaController";
|
|
8
|
-
import { IAgenticaProps } from "./structures/IAgenticaProps";
|
|
9
|
-
import { IAgenticaVendor } from "./structures/IAgenticaVendor";
|
|
10
10
|
/**
|
|
11
11
|
* Nestia A.I. chatbot agent.
|
|
12
12
|
*
|
|
@@ -83,7 +83,7 @@ export declare class Agentica<Model extends ILlmSchema.Model> {
|
|
|
83
83
|
* Get list of operations, which has capsuled the pair of controller
|
|
84
84
|
* and function from the {@link getControllers controllers}.
|
|
85
85
|
*
|
|
86
|
-
* @returns
|
|
86
|
+
* @returns List of operations
|
|
87
87
|
*/
|
|
88
88
|
getOperations(): ReadonlyArray<AgenticaOperation<Model>>;
|
|
89
89
|
/**
|
package/lib/Agentica.js
CHANGED
|
@@ -17,9 +17,9 @@ const AgenticaTokenUsageAggregator_1 = require("./context/internal/AgenticaToken
|
|
|
17
17
|
const AgenticaInitializeEvent_1 = require("./events/AgenticaInitializeEvent");
|
|
18
18
|
const AgenticaRequestEvent_1 = require("./events/AgenticaRequestEvent");
|
|
19
19
|
const AgenticaTextEvent_1 = require("./events/AgenticaTextEvent");
|
|
20
|
+
const __map_take_1 = require("./internal/__map_take");
|
|
20
21
|
const AgenticaOperationComposer_1 = require("./internal/AgenticaOperationComposer");
|
|
21
22
|
const StreamUtil_1 = require("./internal/StreamUtil");
|
|
22
|
-
const __map_take_1 = require("./internal/__map_take");
|
|
23
23
|
const AgenticaTextPrompt_1 = require("./prompts/AgenticaTextPrompt");
|
|
24
24
|
const AgenticaPromptTransformer_1 = require("./transformers/AgenticaPromptTransformer");
|
|
25
25
|
/**
|
|
@@ -69,15 +69,15 @@ class Agentica {
|
|
|
69
69
|
// STATUS
|
|
70
70
|
this.stack_ = [];
|
|
71
71
|
this.listeners_ = new Map();
|
|
72
|
-
this.prompt_histories_ = ((_a = props.histories) !== null && _a !== void 0 ? _a : []).map(
|
|
72
|
+
this.prompt_histories_ = ((_a = props.histories) !== null && _a !== void 0 ? _a : []).map(input => AgenticaPromptTransformer_1.AgenticaPromptTransformer.transform({
|
|
73
73
|
operations: this.operations_.group,
|
|
74
74
|
prompt: input,
|
|
75
75
|
}));
|
|
76
76
|
// STATUS
|
|
77
77
|
this.token_usage_ = AgenticaTokenUsage_1.AgenticaTokenUsage.zero();
|
|
78
78
|
this.ready_ = false;
|
|
79
|
-
this.executor_
|
|
80
|
-
typeof ((_b = props.config) === null || _b === void 0 ? void 0 : _b.executor) === "function"
|
|
79
|
+
this.executor_
|
|
80
|
+
= typeof ((_b = props.config) === null || _b === void 0 ? void 0 : _b.executor) === "function"
|
|
81
81
|
? props.config.executor
|
|
82
82
|
: ChatGptAgent_1.ChatGptAgent.execute((_d = (_c = props.config) === null || _c === void 0 ? void 0 : _c.executor) !== null && _d !== void 0 ? _d : null);
|
|
83
83
|
}
|
|
@@ -114,7 +114,7 @@ class Agentica {
|
|
|
114
114
|
stream: StreamUtil_1.StreamUtil.to(content),
|
|
115
115
|
done: () => true,
|
|
116
116
|
get: () => content,
|
|
117
|
-
join: () => Promise.resolve(content),
|
|
117
|
+
join: () => __awaiter(this, void 0, void 0, function* () { return Promise.resolve(content); }),
|
|
118
118
|
}));
|
|
119
119
|
const newbie = yield this.executor_(this.getContext({
|
|
120
120
|
prompt,
|
|
@@ -151,7 +151,7 @@ class Agentica {
|
|
|
151
151
|
* Get list of operations, which has capsuled the pair of controller
|
|
152
152
|
* and function from the {@link getControllers controllers}.
|
|
153
153
|
*
|
|
154
|
-
* @returns
|
|
154
|
+
* @returns List of operations
|
|
155
155
|
*/
|
|
156
156
|
getOperations() {
|
|
157
157
|
return this.operations_.array;
|
|
@@ -181,7 +181,7 @@ class Agentica {
|
|
|
181
181
|
* @internal
|
|
182
182
|
*/
|
|
183
183
|
getContext(props) {
|
|
184
|
-
const dispatch = (event) => this.dispatch(event);
|
|
184
|
+
const dispatch = (event) => __awaiter(this, void 0, void 0, function* () { return this.dispatch(event); });
|
|
185
185
|
return {
|
|
186
186
|
// APPLICATION
|
|
187
187
|
operations: this.operations_,
|
|
@@ -192,7 +192,7 @@ class Agentica {
|
|
|
192
192
|
ready: () => this.ready_,
|
|
193
193
|
prompt: props.prompt,
|
|
194
194
|
// HANDLERS
|
|
195
|
-
dispatch: (event) => this.dispatch(event),
|
|
195
|
+
dispatch: (event) => __awaiter(this, void 0, void 0, function* () { return this.dispatch(event); }),
|
|
196
196
|
request: (source, body) => __awaiter(this, void 0, void 0, function* () {
|
|
197
197
|
// request information
|
|
198
198
|
const event = new AgenticaRequestEvent_1.AgenticaRequestEvent({
|
|
@@ -205,15 +205,16 @@ class Agentica {
|
|
|
205
205
|
yield dispatch(event);
|
|
206
206
|
// completion
|
|
207
207
|
const completion = yield this.props.vendor.api.chat.completions.create(event.body, event.options);
|
|
208
|
-
const [streamForEvent, temporaryStream] = StreamUtil_1.StreamUtil.transform(completion.toReadableStream(),
|
|
208
|
+
const [streamForEvent, temporaryStream] = StreamUtil_1.StreamUtil.transform(completion.toReadableStream(), value => ChatGptCompletionMessageUtil_1.ChatGptCompletionMessageUtil.transformCompletionChunk(value)).tee();
|
|
209
209
|
const [streamForAggregate, streamForReturn] = temporaryStream.tee();
|
|
210
210
|
void (() => __awaiter(this, void 0, void 0, function* () {
|
|
211
211
|
const reader = streamForAggregate.getReader();
|
|
212
212
|
while (true) {
|
|
213
213
|
const chunk = yield reader.read();
|
|
214
|
-
if (chunk.done)
|
|
214
|
+
if (chunk.done) {
|
|
215
215
|
break;
|
|
216
|
-
|
|
216
|
+
}
|
|
217
|
+
if (chunk.value.usage != null) {
|
|
217
218
|
AgenticaTokenUsageAggregator_1.AgenticaTokenUsageAggregator.aggregate({
|
|
218
219
|
kind: source,
|
|
219
220
|
completionUsage: chunk.value.usage,
|
|
@@ -225,7 +226,7 @@ class Agentica {
|
|
|
225
226
|
const [streamForStream, streamForJoin] = streamForEvent.tee();
|
|
226
227
|
yield dispatch({
|
|
227
228
|
type: "response",
|
|
228
|
-
source
|
|
229
|
+
source,
|
|
229
230
|
stream: streamForStream,
|
|
230
231
|
body: event.body,
|
|
231
232
|
options: event.options,
|
|
@@ -254,6 +255,9 @@ class Agentica {
|
|
|
254
255
|
* @param listener Callback function to be called whenever the event is emitted
|
|
255
256
|
*/
|
|
256
257
|
on(type, listener) {
|
|
258
|
+
/**
|
|
259
|
+
* @TODO remove `as`
|
|
260
|
+
*/
|
|
257
261
|
(0, __map_take_1.__map_take)(this.listeners_, type, () => new Set()).add(listener);
|
|
258
262
|
return this;
|
|
259
263
|
}
|
|
@@ -267,20 +271,23 @@ class Agentica {
|
|
|
267
271
|
*/
|
|
268
272
|
off(type, listener) {
|
|
269
273
|
const set = this.listeners_.get(type);
|
|
270
|
-
if (set) {
|
|
274
|
+
if (set !== undefined) {
|
|
275
|
+
/**
|
|
276
|
+
* @TODO remove `as`
|
|
277
|
+
*/
|
|
271
278
|
set.delete(listener);
|
|
272
|
-
if (set.size === 0)
|
|
279
|
+
if (set.size === 0) {
|
|
273
280
|
this.listeners_.delete(type);
|
|
281
|
+
}
|
|
274
282
|
}
|
|
275
283
|
return this;
|
|
276
284
|
}
|
|
277
285
|
dispatch(event) {
|
|
278
286
|
return __awaiter(this, void 0, void 0, function* () {
|
|
279
287
|
const set = this.listeners_.get(event.type);
|
|
280
|
-
if (set) {
|
|
288
|
+
if (set !== undefined) {
|
|
281
289
|
yield Promise.all(Array.from(set).map((listener) => __awaiter(this, void 0, void 0, function* () {
|
|
282
290
|
try {
|
|
283
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
284
291
|
yield listener(event);
|
|
285
292
|
}
|
|
286
293
|
catch (_a) {
|
package/lib/Agentica.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Agentica.js","sourceRoot":"","sources":["../src/Agentica.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"Agentica.js","sourceRoot":"","sources":["../src/Agentica.ts"],"names":[],"mappings":";;;;;;;;;;;;AAYA,yDAAsD;A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AAK,SAAS,EAAE,CAAC;gBACtB,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAO,QAAQ,EAAE,EAAE;oBACrC,IAAI,CAAC;wBACH,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;oBACxB,CAAC;oBACD,WAAM,CAAC;wBACL,WAAW;oBACb,CAAC;gBACH,CAAC,CAAA,CAAC,CACH,CAAC;YACJ,CAAC;QACH,CAAC;KAAA;CACF;AA7TD,4BA6TC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import { AgenticaContext } from "../context/AgenticaContext";
|
|
3
|
-
import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
4
|
-
import { IAgenticaExecutor } from "../structures/IAgenticaExecutor";
|
|
5
|
-
export declare
|
|
6
|
-
|
|
7
|
-
}
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import type { AgenticaContext } from "../context/AgenticaContext";
|
|
3
|
+
import type { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
4
|
+
import type { IAgenticaExecutor } from "../structures/IAgenticaExecutor";
|
|
5
|
+
export declare const ChatGptAgent: {
|
|
6
|
+
execute: <Model extends ILlmSchema.Model>(executor: Partial<IAgenticaExecutor<Model>> | null) => (ctx: AgenticaContext<Model>) => Promise<AgenticaPrompt<Model>[]>;
|
|
7
|
+
};
|
|
@@ -15,45 +15,50 @@ const ChatGptCancelFunctionAgent_1 = require("./ChatGptCancelFunctionAgent");
|
|
|
15
15
|
const ChatGptDescribeFunctionAgent_1 = require("./ChatGptDescribeFunctionAgent");
|
|
16
16
|
const ChatGptInitializeFunctionAgent_1 = require("./ChatGptInitializeFunctionAgent");
|
|
17
17
|
const ChatGptSelectFunctionAgent_1 = require("./ChatGptSelectFunctionAgent");
|
|
18
|
-
|
|
19
|
-
(function (
|
|
20
|
-
ChatGptAgent.execute = (executor) => (ctx) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
exports.ChatGptAgent = {
|
|
19
|
+
execute: (executor) => (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
20
|
var _a, _b, _c, _d, _e;
|
|
22
21
|
const histories = [];
|
|
23
22
|
// FUNCTIONS ARE NOT LISTED YET
|
|
24
23
|
if (ctx.ready() === false) {
|
|
25
|
-
if ((executor === null || executor === void 0 ? void 0 : executor.initialize) === null)
|
|
24
|
+
if ((executor === null || executor === void 0 ? void 0 : executor.initialize) === null) {
|
|
26
25
|
yield ctx.initialize();
|
|
26
|
+
}
|
|
27
27
|
else {
|
|
28
28
|
histories.push(...(yield ((_a = executor === null || executor === void 0 ? void 0 : executor.initialize) !== null && _a !== void 0 ? _a : ChatGptInitializeFunctionAgent_1.ChatGptInitializeFunctionAgent.execute)(ctx)));
|
|
29
|
-
if (ctx.ready() === false)
|
|
29
|
+
if (ctx.ready() === false) {
|
|
30
30
|
return histories;
|
|
31
|
+
}
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
// CANCEL CANDIDATE FUNCTIONS
|
|
34
|
-
if (ctx.stack.length !== 0)
|
|
35
|
+
if (ctx.stack.length !== 0) {
|
|
35
36
|
histories.push(...(yield ((_b = executor === null || executor === void 0 ? void 0 : executor.cancel) !== null && _b !== void 0 ? _b : ChatGptCancelFunctionAgent_1.ChatGptCancelFunctionAgent.execute)(ctx)));
|
|
37
|
+
}
|
|
36
38
|
// SELECT CANDIDATE FUNCTIONS
|
|
37
39
|
histories.push(...(yield ((_c = executor === null || executor === void 0 ? void 0 : executor.select) !== null && _c !== void 0 ? _c : ChatGptSelectFunctionAgent_1.ChatGptSelectFunctionAgent.execute)(ctx)));
|
|
38
|
-
if (ctx.stack.length === 0)
|
|
40
|
+
if (ctx.stack.length === 0) {
|
|
39
41
|
return histories;
|
|
42
|
+
}
|
|
40
43
|
// FUNCTION CALLING LOOP
|
|
41
44
|
while (true) {
|
|
42
45
|
// EXECUTE FUNCTIONS
|
|
43
46
|
const prompts = yield ((_d = executor === null || executor === void 0 ? void 0 : executor.call) !== null && _d !== void 0 ? _d : ChatGptCallFunctionAgent_1.ChatGptCallFunctionAgent.execute)(ctx);
|
|
44
47
|
histories.push(...prompts);
|
|
45
48
|
// EXPLAIN RETURN VALUES
|
|
46
|
-
const executes = prompts.filter(
|
|
47
|
-
for (const e of executes)
|
|
49
|
+
const executes = prompts.filter(prompt => prompt.type === "execute");
|
|
50
|
+
for (const e of executes) {
|
|
48
51
|
yield ChatGptCancelFunctionAgent_1.ChatGptCancelFunctionAgent.cancelFunction(ctx, {
|
|
49
52
|
reason: "completed",
|
|
50
53
|
name: e.operation.name,
|
|
51
54
|
});
|
|
55
|
+
}
|
|
52
56
|
histories.push(...(yield ((_e = executor === null || executor === void 0 ? void 0 : executor.describe) !== null && _e !== void 0 ? _e : ChatGptDescribeFunctionAgent_1.ChatGptDescribeFunctionAgent.execute)(ctx, executes)));
|
|
53
|
-
if (executes.length === 0 || ctx.stack.length === 0)
|
|
57
|
+
if (executes.length === 0 || ctx.stack.length === 0) {
|
|
54
58
|
break;
|
|
59
|
+
}
|
|
55
60
|
}
|
|
56
61
|
return histories;
|
|
57
|
-
})
|
|
58
|
-
}
|
|
62
|
+
}),
|
|
63
|
+
};
|
|
59
64
|
//# sourceMappingURL=ChatGptAgent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatGptAgent.js","sourceRoot":"","sources":["../../src/chatgpt/ChatGptAgent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,yEAAsE;AACtE,6EAA0E;AAC1E,iFAA8E;AAC9E,qFAAkF;AAClF,6EAA0E;
|
|
1
|
+
{"version":3,"file":"ChatGptAgent.js","sourceRoot":"","sources":["../../src/chatgpt/ChatGptAgent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,yEAAsE;AACtE,6EAA0E;AAC1E,iFAA8E;AAC9E,qFAA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AAS,CAAC;QACnB,CAAC;QAED,wBAAwB;QACxB,OAAO,IAAI,EAAE,CAAC;YACZ,oBAAoB;YACpB,MAAM,OAAO,GAA4B,MAAM,CAC7C,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,mCAAI,mDAAwB,CAAC,OAAO,CACnD,CAAC,GAAG,CAAC,CAAC;YACP,SAAS,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;YAE3B,wBAAwB;YACxB,MAAM,QAAQ,GAAmC,OAAO,CAAC,MAAM,CAC7D,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,CACpC,CAAC;YACF,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;gBACzB,MAAM,uDAA0B,CAAC,cAAc,CAAC,GAAG,EAAE;oBACnD,MAAM,EAAE,WAAW;oBACnB,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI;iBACvB,CAAC,CAAC;YACL,CAAC;YACD,SAAS,CAAC,IAAI,CACZ,GAAG,CAAC,MAAM,CACR,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,QAAQ,mCAAI,2DAA4B,CAAC,OAAO,CAC3D,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAClB,CAAC;YACF,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACpD,MAAM;YACR,CAAC;QACH,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAA;CACF,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import { AgenticaContext } from "../context/AgenticaContext";
|
|
3
|
-
import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
4
|
-
export declare
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import type { AgenticaContext } from "../context/AgenticaContext";
|
|
3
|
+
import type { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
4
|
+
export declare function execute<Model extends ILlmSchema.Model>(ctx: AgenticaContext<Model>): Promise<AgenticaPrompt<Model>[]>;
|
|
5
|
+
export declare const ChatGptCallFunctionAgent: {
|
|
6
|
+
execute: typeof execute;
|
|
7
|
+
};
|