@agentica/core 0.29.5 → 0.30.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/lib/constants/AgenticaSystemPrompt.d.ts +1 -0
- package/lib/constants/AgenticaSystemPrompt.js +2 -1
- package/lib/constants/AgenticaSystemPrompt.js.map +1 -1
- package/lib/events/AgenticaEvent.d.ts +3 -1
- package/lib/events/AgenticaJsonParseErrorEvent.d.ts +8 -0
- package/lib/events/AgenticaJsonParseErrorEvent.js +3 -0
- package/lib/events/AgenticaJsonParseErrorEvent.js.map +1 -0
- package/lib/events/MicroAgenticaEvent.d.ts +3 -1
- package/lib/events/index.d.ts +1 -0
- package/lib/events/index.js +1 -0
- package/lib/events/index.js.map +1 -1
- package/lib/factory/events.d.ts +8 -1
- package/lib/factory/events.js +14 -2
- package/lib/factory/events.js.map +1 -1
- package/lib/functional/assertHttpController.js +14 -14
- package/lib/functional/assertHttpLlmApplication.js +14 -14
- package/lib/functional/validateHttpController.js +14 -14
- package/lib/functional/validateHttpLlmApplication.js +14 -14
- package/lib/index.mjs +764 -1722
- package/lib/index.mjs.map +1 -1
- package/lib/json/IAgenticaEventJson.d.ts +18 -5
- package/lib/orchestrate/call.d.ts +1 -1
- package/lib/orchestrate/call.js +199 -285
- package/lib/orchestrate/call.js.map +1 -1
- package/lib/orchestrate/cancel.js +23 -20
- package/lib/orchestrate/cancel.js.map +1 -1
- package/lib/orchestrate/initialize.js +565 -1560
- package/lib/orchestrate/initialize.js.map +1 -1
- package/lib/orchestrate/select.js +24 -21
- package/lib/orchestrate/select.js.map +1 -1
- package/lib/structures/IAgenticaSystemPrompt.d.ts +31 -0
- package/lib/structures/IMicroAgenticaSystemPrompt.d.ts +31 -0
- package/package.json +5 -5
- package/prompts/json_parse_error.md +32 -0
- package/prompts/validate.md +61 -13
- package/src/constants/AgenticaSystemPrompt.ts +3 -1
- package/src/events/AgenticaEvent.ts +3 -0
- package/src/events/AgenticaJsonParseErrorEvent.ts +12 -0
- package/src/events/MicroAgenticaEvent.ts +4 -1
- package/src/events/index.ts +1 -0
- package/src/factory/events.ts +19 -1
- package/src/json/IAgenticaEventJson.ts +20 -4
- package/src/orchestrate/call.ts +273 -389
- package/src/orchestrate/initialize.ts +2 -2
- package/src/orchestrate/select.ts +2 -2
- package/src/structures/IAgenticaSystemPrompt.ts +32 -0
- package/src/structures/IMicroAgenticaSystemPrompt.ts +32 -0
|
@@ -9,7 +9,7 @@ import type { AgenticaAssistantMessageEvent } from "../events/AgenticaAssistantM
|
|
|
9
9
|
|
|
10
10
|
import { AgenticaDefaultPrompt } from "../constants/AgenticaDefaultPrompt";
|
|
11
11
|
import { AgenticaSystemPrompt } from "../constants/AgenticaSystemPrompt";
|
|
12
|
-
import {
|
|
12
|
+
import { createAssistantMessageEvent } from "../factory/events";
|
|
13
13
|
import { decodeHistory, decodeUserMessageContent } from "../factory/histories";
|
|
14
14
|
import { ChatGptCompletionMessageUtil } from "../utils/ChatGptCompletionMessageUtil";
|
|
15
15
|
import { MPSC } from "../utils/MPSC";
|
|
@@ -106,7 +106,7 @@ export async function initialize<Model extends ILlmSchema.Model>(ctx: AgenticaCo
|
|
|
106
106
|
};
|
|
107
107
|
mpsc.produce(choice.delta.content);
|
|
108
108
|
|
|
109
|
-
const event: AgenticaAssistantMessageEvent =
|
|
109
|
+
const event: AgenticaAssistantMessageEvent = createAssistantMessageEvent({
|
|
110
110
|
stream: streamDefaultReaderToAsyncGenerator(mpsc.consumer.getReader()),
|
|
111
111
|
done: () => mpsc.done(),
|
|
112
112
|
get: () => textContext[choice.index]!.content,
|
|
@@ -15,7 +15,7 @@ import type { AgenticaEvent } from "../events/AgenticaEvent";
|
|
|
15
15
|
import { AgenticaConstant } from "../constants/AgenticaConstant";
|
|
16
16
|
import { AgenticaDefaultPrompt } from "../constants/AgenticaDefaultPrompt";
|
|
17
17
|
import { AgenticaSystemPrompt } from "../constants/AgenticaSystemPrompt";
|
|
18
|
-
import {
|
|
18
|
+
import { createAssistantMessageEvent } from "../factory/events";
|
|
19
19
|
import { decodeHistory, decodeUserMessageContent } from "../factory/histories";
|
|
20
20
|
import { ChatGptCompletionMessageUtil } from "../utils/ChatGptCompletionMessageUtil";
|
|
21
21
|
import { StreamUtil, toAsyncGenerator } from "../utils/StreamUtil";
|
|
@@ -237,7 +237,7 @@ async function step<Model extends ILlmSchema.Model>(
|
|
|
237
237
|
&& choice.message.content != null
|
|
238
238
|
&& choice.message.content.length !== 0
|
|
239
239
|
) {
|
|
240
|
-
const event: AgenticaAssistantMessageEvent =
|
|
240
|
+
const event: AgenticaAssistantMessageEvent = createAssistantMessageEvent({
|
|
241
241
|
stream: toAsyncGenerator(choice.message.content),
|
|
242
242
|
join: async () => Promise.resolve(choice.message.content!),
|
|
243
243
|
done: () => true,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
+
import type { AgenticaJsonParseErrorEvent } from "../events";
|
|
3
4
|
import type { AgenticaValidateEvent } from "../events/AgenticaValidateEvent";
|
|
4
5
|
import type { AgenticaExecuteHistory } from "../histories/AgenticaExecuteHistory";
|
|
5
6
|
import type { AgenticaHistory } from "../histories/AgenticaHistory";
|
|
@@ -174,6 +175,37 @@ export interface IAgenticaSystemPrompt<Model extends ILlmSchema.Model> {
|
|
|
174
175
|
*/
|
|
175
176
|
validate?: (events: AgenticaValidateEvent<Model>[]) => string;
|
|
176
177
|
|
|
178
|
+
/**
|
|
179
|
+
* JSON parsing error system prompt.
|
|
180
|
+
*
|
|
181
|
+
* When the AI generates function arguments with invalid JSON syntax
|
|
182
|
+
* that cannot be parsed by `JSON.parse()`, this prompt provides system
|
|
183
|
+
* instructions for handling the parsing error and requesting corrected
|
|
184
|
+
* function calls.
|
|
185
|
+
*
|
|
186
|
+
* This specialized prompt enables the AI to:
|
|
187
|
+
* - Understand that the function call arguments contained malformed JSON
|
|
188
|
+
* - Receive the specific error message from `JSON.parse()`
|
|
189
|
+
* - Get guidance on common JSON syntax issues (trailing commas, quote problems, etc.)
|
|
190
|
+
* - Retry the function call with properly formatted JSON arguments
|
|
191
|
+
*
|
|
192
|
+
* The JSON parse error prompt acts as an immediate correction mechanism
|
|
193
|
+
* when function calling fails at the JSON parsing stage, before any
|
|
194
|
+
* schema validation occurs. This ensures that basic JSON syntax compliance
|
|
195
|
+
* is maintained for all function calls.
|
|
196
|
+
*
|
|
197
|
+
* Key features include:
|
|
198
|
+
* - Direct error message reporting from `JSON.parse()`
|
|
199
|
+
* - Clear identification of the problematic function call
|
|
200
|
+
* - Specific guidance on JSON syntax requirements
|
|
201
|
+
* - Immediate retry instruction without additional processing
|
|
202
|
+
*
|
|
203
|
+
* @param event The JSON parse error event containing the malformed arguments and error details
|
|
204
|
+
* @returns JSON parse error system prompt
|
|
205
|
+
* @default Built-in JSON parse error prompt optimized for syntax correction
|
|
206
|
+
*/
|
|
207
|
+
jsonParseError?: (event: AgenticaJsonParseErrorEvent<Model>) => string;
|
|
208
|
+
|
|
177
209
|
/**
|
|
178
210
|
* Describe system prompt.
|
|
179
211
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
+
import type { AgenticaJsonParseErrorEvent } from "../events/AgenticaJsonParseErrorEvent";
|
|
3
4
|
import type { AgenticaValidateEvent } from "../events/AgenticaValidateEvent";
|
|
4
5
|
import type { AgenticaExecuteHistory } from "../histories/AgenticaExecuteHistory";
|
|
5
6
|
import type { MicroAgenticaHistory } from "../histories/MicroAgenticaHistory";
|
|
@@ -107,6 +108,37 @@ export interface IMicroAgenticaSystemPrompt<Model extends ILlmSchema.Model> {
|
|
|
107
108
|
*/
|
|
108
109
|
validate?: (events: AgenticaValidateEvent<Model>[]) => string;
|
|
109
110
|
|
|
111
|
+
/**
|
|
112
|
+
* JSON parsing error system prompt.
|
|
113
|
+
*
|
|
114
|
+
* When the AI generates function arguments with invalid JSON syntax
|
|
115
|
+
* that cannot be parsed by `JSON.parse()`, this prompt provides system
|
|
116
|
+
* instructions for handling the parsing error and requesting corrected
|
|
117
|
+
* function calls.
|
|
118
|
+
*
|
|
119
|
+
* This specialized prompt enables the AI to:
|
|
120
|
+
* - Understand that the function call arguments contained malformed JSON
|
|
121
|
+
* - Receive the specific error message from `JSON.parse()`
|
|
122
|
+
* - Get guidance on common JSON syntax issues (trailing commas, quote problems, etc.)
|
|
123
|
+
* - Retry the function call with properly formatted JSON arguments
|
|
124
|
+
*
|
|
125
|
+
* The JSON parse error prompt acts as an immediate correction mechanism
|
|
126
|
+
* when function calling fails at the JSON parsing stage, before any
|
|
127
|
+
* schema validation occurs. This ensures that basic JSON syntax compliance
|
|
128
|
+
* is maintained for all function calls.
|
|
129
|
+
*
|
|
130
|
+
* Key features include:
|
|
131
|
+
* - Direct error message reporting from `JSON.parse()`
|
|
132
|
+
* - Clear identification of the problematic function call
|
|
133
|
+
* - Specific guidance on JSON syntax requirements
|
|
134
|
+
* - Immediate retry instruction without additional processing
|
|
135
|
+
*
|
|
136
|
+
* @param event The JSON parse error event containing the malformed arguments and error details
|
|
137
|
+
* @returns JSON parse error system prompt
|
|
138
|
+
* @default Built-in JSON parse error prompt optimized for syntax correction
|
|
139
|
+
*/
|
|
140
|
+
jsonParseError?: (event: AgenticaJsonParseErrorEvent<Model>) => string;
|
|
141
|
+
|
|
110
142
|
/**
|
|
111
143
|
* Describe system prompt.
|
|
112
144
|
*
|