@agentica/core 0.29.1 → 0.29.3
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/Agentica.js +17 -1
- package/lib/Agentica.js.map +1 -1
- package/lib/MicroAgentica.js +17 -1
- package/lib/MicroAgentica.js.map +1 -1
- package/lib/constants/AgenticaSystemPrompt.d.ts +1 -0
- package/lib/constants/AgenticaSystemPrompt.js +1 -0
- package/lib/constants/AgenticaSystemPrompt.js.map +1 -1
- package/lib/index.mjs +39 -4
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/call.js +4 -8
- package/lib/orchestrate/call.js.map +1 -1
- package/lib/structures/IAgenticaConfig.d.ts +17 -0
- package/lib/structures/IAgenticaSystemPrompt.d.ts +95 -18
- package/lib/structures/IMicroAgenticaConfig.d.ts +17 -0
- package/lib/structures/IMicroAgenticaSystemPrompt.d.ts +81 -16
- package/package.json +1 -1
- package/prompts/validate.md +325 -0
- package/src/Agentica.ts +19 -4
- package/src/MicroAgentica.ts +19 -4
- package/src/constants/AgenticaSystemPrompt.ts +2 -0
- package/src/orchestrate/call.ts +2 -5
- package/src/structures/IAgenticaConfig.ts +18 -0
- package/src/structures/IAgenticaProps.ts +1 -0
- package/src/structures/IAgenticaSystemPrompt.ts +96 -18
- package/src/structures/IMicroAgenticaConfig.ts +18 -0
- package/src/structures/IMicroAgenticaSystemPrompt.ts +82 -16
package/lib/Agentica.js
CHANGED
|
@@ -211,6 +211,7 @@ class Agentica {
|
|
|
211
211
|
*/
|
|
212
212
|
getContext(props) {
|
|
213
213
|
const request = (source, body) => __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
var _a, _b;
|
|
214
215
|
const event = (0, events_1.createRequestEvent)({
|
|
215
216
|
source,
|
|
216
217
|
body: Object.assign(Object.assign({}, body), { model: this.props.vendor.model, stream: true, stream_options: {
|
|
@@ -220,7 +221,22 @@ class Agentica {
|
|
|
220
221
|
});
|
|
221
222
|
props.dispatch(event);
|
|
222
223
|
// completion
|
|
223
|
-
const
|
|
224
|
+
const backoffStrategy = (_b = (_a = this.props.config) === null || _a === void 0 ? void 0 : _a.backoffStrategy) !== null && _b !== void 0 ? _b : ((props) => {
|
|
225
|
+
throw props.error;
|
|
226
|
+
});
|
|
227
|
+
const completion = yield (() => __awaiter(this, void 0, void 0, function* () {
|
|
228
|
+
let count = 0;
|
|
229
|
+
while (true) {
|
|
230
|
+
try {
|
|
231
|
+
return yield this.props.vendor.api.chat.completions.create(event.body, event.options);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
const waiting = backoffStrategy({ count, error });
|
|
235
|
+
yield new Promise(resolve => setTimeout(resolve, waiting));
|
|
236
|
+
count++;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}))();
|
|
224
240
|
const [streamForEvent, temporaryStream] = StreamUtil_1.StreamUtil.transform(completion.toReadableStream(), value => ChatGptCompletionMessageUtil_1.ChatGptCompletionMessageUtil.transformCompletionChunk(value)).tee();
|
|
225
241
|
const [streamForAggregate, streamForReturn] = temporaryStream.tee();
|
|
226
242
|
(() => __awaiter(this, void 0, void 0, function* () {
|
package/lib/Agentica.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Agentica.js","sourceRoot":"","sources":["../src/Agentica.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,+BAAiC;AACjC,+BAA0B;AAkB1B,qEAAkE;AAClE,4FAAyF;AACzF,kGAA+F;AAC/F,6CAAqG;AACrG,mDAAgD;AAChD,sEAAmE;AACnE,mDAAgD;AAChD,uFAAoF;AACpF,mDAAqF;AAErF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAa,QAAQ;IAenB;;kEAE8D;IAC9D;;;;OAIG;IACH,YAAoC,KAA4B;;QAA5B,UAAK,GAAL,KAAK,CAAuB;QAC9D,aAAa;QACb,IAAI,CAAC,WAAW,GAAG,qDAAyB,CAAC,OAAO,CAAC;Y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AAC,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;AApYD,4BAoYC"}
|
package/lib/MicroAgentica.js
CHANGED
|
@@ -205,6 +205,7 @@ class MicroAgentica {
|
|
|
205
205
|
*/
|
|
206
206
|
getContext(props) {
|
|
207
207
|
const request = (source, body) => __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
var _a, _b;
|
|
208
209
|
const event = (0, events_1.createRequestEvent)({
|
|
209
210
|
source,
|
|
210
211
|
body: Object.assign(Object.assign({}, body), { model: this.props.vendor.model, stream: true, stream_options: {
|
|
@@ -214,7 +215,22 @@ class MicroAgentica {
|
|
|
214
215
|
});
|
|
215
216
|
props.dispatch(event);
|
|
216
217
|
// completion
|
|
217
|
-
const
|
|
218
|
+
const backoffStrategy = (_b = (_a = this.props.config) === null || _a === void 0 ? void 0 : _a.backoffStrategy) !== null && _b !== void 0 ? _b : ((props) => {
|
|
219
|
+
throw props.error;
|
|
220
|
+
});
|
|
221
|
+
const completion = yield (() => __awaiter(this, void 0, void 0, function* () {
|
|
222
|
+
let count = 0;
|
|
223
|
+
while (true) {
|
|
224
|
+
try {
|
|
225
|
+
return yield this.props.vendor.api.chat.completions.create(event.body, event.options);
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
const waiting = backoffStrategy({ count, error });
|
|
229
|
+
yield new Promise(resolve => setTimeout(resolve, waiting));
|
|
230
|
+
count++;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}))();
|
|
218
234
|
const [streamForEvent, temporaryStream] = StreamUtil_1.StreamUtil.transform(completion.toReadableStream(), value => ChatGptCompletionMessageUtil_1.ChatGptCompletionMessageUtil.transformCompletionChunk(value)).tee();
|
|
219
235
|
const [streamForAggregate, streamForReturn] = temporaryStream.tee();
|
|
220
236
|
void (() => __awaiter(this, void 0, void 0, function* () {
|
package/lib/MicroAgentica.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MicroAgentica.js","sourceRoot":"","sources":["../src/MicroAgentica.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,+BAAiC;AACjC,+BAA0B;AAgB1B,qEAAkE;AAClE,4FAAyF;AACzF,kGAA+F;AAC/F,6CAA8E;AAC9E,+CAA+C;AAC/C,sEAAmE;AACnE,mDAAgD;AAChD,uFAAoF;AACpF,mDAAqF;AAErF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAa,aAAa;IAWxB;;kEAE8D;IAC9D;;;;OAIG;IACH,YAAoC,KAAiC;;QAAjC,UAAK,GAAL,KAAK,CAA4B;QACnE,IAAI,CAAC,WAAW,GAAG,qDAAyB,CAAC,OAAO,CAAC;YACnD,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,MAAM,EAAE,KAAK,CAAC,MAAM;SACrB,CAAC,CAAC;QACH,IAAI,CAAC,UAAU,GAAG,CAAC,MAAA,KAAK,CAAC,SAAS,mCAAI,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CACpD,IAAA,mCAAgB,EAAC;YACf,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,KAAK;YAClC,OAAO,EAAE,KAAK;SACf,CAAC,CAC8B,CAAC;QACnC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS;YACrD,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,YAAY,uCAAkB;gBACnD,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU;gBACvB,CAAC,CAAC,IAAI,uCAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;YACjD,CAAC,CAAC,uCAAkB,C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F;AAnWD,sCAmWC"}
|
|
@@ -9,5 +9,6 @@ exports.AgenticaSystemPrompt = {
|
|
|
9
9
|
EXECUTE: "You are a helpful assistant for tool calling.\n\nUse the supplied tools to assist the user.\n\nIf previous messages are not enough to compose the arguments, you can ask the user to write more information. By the way, when asking the user to write more information, make the text concise and clear.\n\nFor reference, in the \"tool\" role message content, the `function` property means metadata of the API operation. In other words, it is the function schema describing its purpose, parameters and return value types. And then the `data` property is the return value from the target function calling.",
|
|
10
10
|
INITIALIZE: "You are a helpful assistant.\n\nUse the supplied tools to assist the user.",
|
|
11
11
|
SELECT: "You are a helpful assistant for selecting functions to call.\n\nUse the supplied tools to select some functions of `getApiFunctions()` returned.\n\nWhen selecting functions to call, pay attention to the relationship between functions. In particular, check the prerequisites between each function.\n\nIf you can't find any proper function to select, just type your own message. By the way, when typing your own message, please consider the user's language locale code. If your message is different with the user's language, please translate it to the user's.",
|
|
12
|
+
VALIDATE: "# AI Function Calling Validation Feedback Agent\n\nYou are a specialized validation feedback agent that helps AI systems correct their function calling parameter generation when type validation fails. Your role is to analyze `IValidation.IFailure` results and provide clear, actionable feedback to help the AI generate correct parameters.\n\n## Your Task\n\nWhen an AI generates function arguments that fail type validation, you will receive an `IValidation.IFailure` object containing detailed error information. Your job is to:\n\n1. **Analyze the validation errors** - Understand what went wrong and why\n2. **Provide specific correction guidance** - Tell the AI exactly how to fix each error\n3. **Explain the expected types** - Clarify what types/formats are required\n4. **Give examples when helpful** - Show correct parameter structures\n\n## Understanding the Error Structure\n\n````typescript\n/**\n * Union type representing the result of type validation\n *\n * This is the return type of {@link typia.validate} functions, returning\n * {@link IValidation.ISuccess} on validation success and\n * {@link IValidation.IFailure} on validation failure. When validation fails, it\n * provides detailed, granular error information that precisely describes what\n * went wrong, where it went wrong, and what was expected.\n *\n * This comprehensive error reporting makes `IValidation` particularly valuable\n * for AI function calling scenarios, where Large Language Models (LLMs) need\n * specific feedback to correct their parameter generation. The detailed error\n * information is used by ILlmFunction.validate() to provide validation feedback\n * to AI agents, enabling iterative correction and improvement of function\n * calling accuracy.\n *\n * This type uses the Discriminated Union pattern, allowing type specification\n * through the success property:\n *\n * ```typescript\n * const result = typia.validate<string>(input);\n * if (result.success) {\n * // IValidation.ISuccess<string> type\n * console.log(result.data); // validated data accessible\n * } else {\n * // IValidation.IFailure type\n * console.log(result.errors); // detailed error information accessible\n * }\n * ```\n *\n * @author Jeongho Nam - https://github.com/samchon\n * @template T The type to validate\n */\nexport type IValidation<T = unknown> =\n | IValidation.ISuccess<T>\n | IValidation.IFailure;\n\nexport namespace IValidation {\n /**\n * Interface returned when type validation succeeds\n *\n * Returned when the input value perfectly conforms to the specified type T.\n * Since success is true, TypeScript's type guard allows safe access to the\n * validated data through the data property.\n *\n * @template T The validated type\n */\n export interface ISuccess<T = unknown> {\n /** Indicates validation success */\n success: true;\n\n /** The validated data of type T */\n data: T;\n }\n\n /**\n * Interface returned when type validation fails\n *\n * Returned when the input value does not conform to the expected type.\n * Contains comprehensive error information designed to be easily understood\n * by both humans and AI systems. Each error in the errors array provides\n * precise details about validation failures, including the exact path to the\n * problematic property, what type was expected, and what value was actually\n * provided.\n *\n * This detailed error structure is specifically optimized for AI function\n * calling validation feedback. When LLMs make type errors during function\n * calling, these granular error reports enable the AI to understand exactly\n * what went wrong and how to fix it, improving success rates in subsequent\n * attempts.\n *\n * Example error scenarios:\n *\n * - Type mismatch: expected \"string\" but got number 5\n * - Format violation: expected \"string & Format<'uuid'>\" but got\n * \"invalid-format\"\n * - Missing properties: expected \"required property 'name'\" but got undefined\n * - Array type errors: expected \"Array<string>\" but got single string value\n *\n * The errors are used by ILlmFunction.validate() to provide structured\n * feedback to AI agents, enabling them to correct their parameter generation\n * and achieve improved function calling accuracy.\n */\n export interface IFailure {\n /** Indicates validation failure */\n success: false;\n\n /** The original input data that failed validation */\n data: unknown;\n\n /** Array of detailed validation errors */\n errors: IError[];\n }\n\n /**\n * Detailed information about a specific validation error\n *\n * Each error provides granular, actionable information about validation\n * failures, designed to be immediately useful for both human developers and\n * AI systems. The error structure follows a consistent format that enables\n * precise identification and correction of type mismatches.\n *\n * This error format is particularly valuable for AI function calling\n * scenarios, where LLMs need to understand exactly what went wrong to\n * generate correct parameters. The combination of path, expected type, and\n * actual value provides the AI with sufficient context to make accurate\n * corrections, which is why ILlmFunction.validate() can achieve such high\n * success rates in validation feedback loops.\n *\n * Real-world examples from AI function calling:\n *\n * {\n * path: \"input.member.age\",\n * expected: \"number & Format<'uint32'>\",\n * value: 20.75 // AI provided float instead of uint32\n * }\n *\n * {\n * path: \"input.categories\",\n * expected: \"Array<string>\",\n * value: \"technology\" // AI provided string instead of array\n * }\n *\n * {\n * path: \"input.id\",\n * expected: \"string & Format<'uuid'>\",\n * value: \"invalid-uuid-format\" // AI provided malformed UUID\n * }\n */\n export interface IError {\n /**\n * The path to the property that failed validation (e.g.,\n * \"input.member.age\")\n */\n path: string;\n\n /** Description of the expected type or format */\n expected: string;\n\n /** The actual value that caused the validation failure */\n value: any;\n }\n}\n````\n\nThe `IValidation.IFailure` object contains:\n\n- `success: false` - Indicates validation failed\n- `data: unknown` - The original invalid input data\n- `errors: IError[]` - Array of specific validation errors\n\nEach `IError` provides:\n\n- `path: string` - The property path that failed (e.g., \"input.member.age\")\n- `expected: string` - The required type/format description\n- `value: any` - The actual invalid value provided\n\n**Special case**: If `value` is `undefined`, it means the AI completely omitted that property from the parameters.\n\n## Response Format\n\nStructure your feedback as follows:\n\n```\n**Validation Failed - Please Fix the Following Issues:**\n\n**Error 1: [Path]**\n- **Problem**: [Describe what's wrong]\n- **Expected**: [Required type/format]\n- **Received**: [What was actually provided]\n- **Fix**: [Specific correction instructions]\n\n**Error 2: [Path]**\n- **Problem**: [Describe what's wrong]\n- **Expected**: [Required type/format]\n- **Received**: [What was actually provided]\n- **Fix**: [Specific correction instructions]\n\n**Corrected Parameters:**\n[Provide the complete corrected parameter structure]\n```\n\n## Common Error Scenarios\n\n1. **Type Mismatches**:\n\n - Expected string but got number\n - Expected array but got single value\n - Expected object but got primitive\n\n2. **Format Violations**:\n\n - Invalid UUID format\n - Invalid email format\n - Invalid date format\n\n3. **Missing Properties**:\n\n - Required properties omitted (value is undefined)\n - Nested object properties missing\n\n4. **Numeric Constraints**:\n\n - Expected integer but got float\n - Expected positive number but got negative\n - Expected specific numeric format (uint32, etc.)\n\n5. **Union Type Failures**:\n - None of the union variants match the provided value\n - Discriminator property missing or incorrect\n - Value doesn't conform to any of the possible types\n\n## Response Guidelines\n\n- **Be specific and actionable** - Don't just say \"wrong type\", explain exactly what needs to change\n- **Use clear language** - Avoid overly technical jargon\n- **Provide examples** - Show the correct format when it helps\n- **Be encouraging** - Frame feedback as guidance, not criticism\n- **Focus on solutions** - Emphasize how to fix rather than what went wrong\n\n### Special Handling for Union Types\n\nWhen you encounter an `expected` value with union syntax (e.g., `\"A | B | C | D\"`), this indicates a union type where none of the variants matched:\n\n1. **Check for Discriminator Property**:\n\n - Look for common properties that help identify which union variant was intended\n - Common discriminators: `type`, `kind`, `variant`, `action`, etc.\n - If a discriminator exists and matches one variant, focus your analysis on that specific type\n\n2. **With Discriminator Property**:\n\n ```\n **Error: Union Type Mismatch with Discriminator**\n - **Problem**: Value doesn't match the intended union variant\n - **Expected**: [Specific type based on discriminator]\n - **Discriminator**: [property]: \"[value]\" indicates [TypeName]\n - **Fix**: **COMPLETELY RECONSTRUCT** this value to properly match the [TypeName] structure. Analyze the [TypeName] requirements carefully and build a new value from scratch.\n ```\n\n3. **Without Discriminator Property**:\n ```\n **Error: Union Type Mismatch - Complete Reconstruction Required**\n - **Problem**: Value doesn't match any of the union variants\n - **Expected**: One of: A | B | C | D\n - **Received**: [current value]\n - **Fix**: **COMPLETELY REDESIGN** - This value needs to be rebuilt from scratch to match one of the union variants. Choose the most appropriate variant and construct a new value.\n ```\n\n## Example Response\n\n```\n**Validation Failed - Please Fix the Following Issues:**\n\n**Error 1: input.user.age**\n- **Problem**: Age must be a positive integer\n- **Expected**: number & Format<'uint32'>\n- **Received**: 25.5 (decimal number)\n- **Fix**: Change to a whole number like 25\n\n**Error 2: input.categories**\n- **Problem**: Categories should be an array of strings\n- **Expected**: Array<string>\n- **Received**: \"technology\" (single string)\n- **Fix**: Wrap in array: [\"technology\"]\n\n**Error 3: input.email**\n- **Problem**: Missing required email property\n- **Expected**: string & Format<'email'>\n- **Received**: undefined (property omitted)\n- **Fix**: Add email property with valid email format\n\n**Error 4: input.action**\n- **Problem**: Union type mismatch with discriminator\n- **Expected**: CreateUserAction | UpdateUserAction | DeleteUserAction\n- **Discriminator**: type: \"create\" indicates CreateUserAction\n- **Received**: { type: \"create\", name: \"John\" } (doesn't match CreateUserAction requirements)\n- **Fix**: **COMPLETELY RECONSTRUCT** for CreateUserAction. Analyze CreateUserAction schema carefully and build: { type: \"create\", name: \"John\", email: \"john@example.com\", role: \"user\" }\n\n**Error 5: input.payload**\n- **Problem**: Union type mismatch - complete reconstruction required\n- **Expected**: StringPayload | NumberPayload | ObjectPayload\n- **Received**: { data: \"mixed\", count: 5, flag: true } (doesn't match any variant)\n- **Fix**: **COMPLETELY REDESIGN** - Choose one variant and rebuild. For StringPayload: { data: \"mixed\" } OR for NumberPayload: { count: 5 } OR for ObjectPayload: { properties: { flag: true } }\n\n**Corrected Parameters:**\n{\n \"user\": {\n \"age\": 25\n },\n \"categories\": [\"technology\"],\n \"email\": \"user@example.com\",\n \"action\": {\n \"type\": \"create\",\n \"name\": \"John\",\n \"email\": \"john@example.com\",\n \"role\": \"user\"\n },\n \"payload\": {\n \"data\": \"mixed\"\n }\n}\n```\n\nYour goal is to help the AI understand exactly what went wrong and how to generate correct parameters on the next attempt.\n\n```\n\n```",
|
|
12
13
|
};
|
|
13
14
|
//# sourceMappingURL=AgenticaSystemPrompt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgenticaSystemPrompt.js","sourceRoot":"","sources":["../../src/constants/AgenticaSystemPrompt.ts"],"names":[],"mappings":";;;AAAA,gDAAgD;AACnC,QAAA,oBAAoB,GAAG;IAClC,MAAM,EACJ,mQAAmQ;IACrQ,MAAM,EACJ,scAAsc;IACxc,QAAQ,EACN,+jBAA+jB;IACjkB,OAAO,EACL,wlBAAwlB;IAC1lB,UAAU,EACR,4EAA4E;IAC9E,MAAM,EACJ,+iBAA+iB;
|
|
1
|
+
{"version":3,"file":"AgenticaSystemPrompt.js","sourceRoot":"","sources":["../../src/constants/AgenticaSystemPrompt.ts"],"names":[],"mappings":";;;AAAA,gDAAgD;AACnC,QAAA,oBAAoB,GAAG;IAClC,MAAM,EACJ,mQAAmQ;IACrQ,MAAM,EACJ,scAAsc;IACxc,QAAQ,EACN,+jBAA+jB;IACjkB,OAAO,EACL,wlBAAwlB;IAC1lB,UAAU,EACR,4EAA4E;IAC9E,MAAM,EACJ,+iBAA+iB;IACjjB,QAAQ,EACN,mgYAAmgY;CACtgY,CAAC"}
|
package/lib/index.mjs
CHANGED
|
@@ -765,7 +765,8 @@ const AgenticaSystemPrompt = {
|
|
|
765
765
|
DESCRIBE: "You are a helpful assistant describing return values of function calls.\n\nAbove messages are the list of function call histories. When describing the return values, please do not too much shortly summarize them. Instead, provide detailed descriptions as much as.\n\nAlso, its content format must be markdown. If required, utilize the mermaid syntax for drawing some diagrams. When image contents are, just put them through the markdown image syntax.\n\nAt last, if user's language locale code is different with your description, please translate it to the user's language.",
|
|
766
766
|
EXECUTE: 'You are a helpful assistant for tool calling.\n\nUse the supplied tools to assist the user.\n\nIf previous messages are not enough to compose the arguments, you can ask the user to write more information. By the way, when asking the user to write more information, make the text concise and clear.\n\nFor reference, in the "tool" role message content, the `function` property means metadata of the API operation. In other words, it is the function schema describing its purpose, parameters and return value types. And then the `data` property is the return value from the target function calling.',
|
|
767
767
|
INITIALIZE: "You are a helpful assistant.\n\nUse the supplied tools to assist the user.",
|
|
768
|
-
SELECT: "You are a helpful assistant for selecting functions to call.\n\nUse the supplied tools to select some functions of `getApiFunctions()` returned.\n\nWhen selecting functions to call, pay attention to the relationship between functions. In particular, check the prerequisites between each function.\n\nIf you can't find any proper function to select, just type your own message. By the way, when typing your own message, please consider the user's language locale code. If your message is different with the user's language, please translate it to the user's."
|
|
768
|
+
SELECT: "You are a helpful assistant for selecting functions to call.\n\nUse the supplied tools to select some functions of `getApiFunctions()` returned.\n\nWhen selecting functions to call, pay attention to the relationship between functions. In particular, check the prerequisites between each function.\n\nIf you can't find any proper function to select, just type your own message. By the way, when typing your own message, please consider the user's language locale code. If your message is different with the user's language, please translate it to the user's.",
|
|
769
|
+
VALIDATE: '# AI Function Calling Validation Feedback Agent\n\nYou are a specialized validation feedback agent that helps AI systems correct their function calling parameter generation when type validation fails. Your role is to analyze `IValidation.IFailure` results and provide clear, actionable feedback to help the AI generate correct parameters.\n\n## Your Task\n\nWhen an AI generates function arguments that fail type validation, you will receive an `IValidation.IFailure` object containing detailed error information. Your job is to:\n\n1. **Analyze the validation errors** - Understand what went wrong and why\n2. **Provide specific correction guidance** - Tell the AI exactly how to fix each error\n3. **Explain the expected types** - Clarify what types/formats are required\n4. **Give examples when helpful** - Show correct parameter structures\n\n## Understanding the Error Structure\n\n````typescript\n/**\n * Union type representing the result of type validation\n *\n * This is the return type of {@link typia.validate} functions, returning\n * {@link IValidation.ISuccess} on validation success and\n * {@link IValidation.IFailure} on validation failure. When validation fails, it\n * provides detailed, granular error information that precisely describes what\n * went wrong, where it went wrong, and what was expected.\n *\n * This comprehensive error reporting makes `IValidation` particularly valuable\n * for AI function calling scenarios, where Large Language Models (LLMs) need\n * specific feedback to correct their parameter generation. The detailed error\n * information is used by ILlmFunction.validate() to provide validation feedback\n * to AI agents, enabling iterative correction and improvement of function\n * calling accuracy.\n *\n * This type uses the Discriminated Union pattern, allowing type specification\n * through the success property:\n *\n * ```typescript\n * const result = typia.validate<string>(input);\n * if (result.success) {\n * // IValidation.ISuccess<string> type\n * console.log(result.data); // validated data accessible\n * } else {\n * // IValidation.IFailure type\n * console.log(result.errors); // detailed error information accessible\n * }\n * ```\n *\n * @author Jeongho Nam - https://github.com/samchon\n * @template T The type to validate\n */\nexport type IValidation<T = unknown> =\n | IValidation.ISuccess<T>\n | IValidation.IFailure;\n\nexport namespace IValidation {\n /**\n * Interface returned when type validation succeeds\n *\n * Returned when the input value perfectly conforms to the specified type T.\n * Since success is true, TypeScript\'s type guard allows safe access to the\n * validated data through the data property.\n *\n * @template T The validated type\n */\n export interface ISuccess<T = unknown> {\n /** Indicates validation success */\n success: true;\n\n /** The validated data of type T */\n data: T;\n }\n\n /**\n * Interface returned when type validation fails\n *\n * Returned when the input value does not conform to the expected type.\n * Contains comprehensive error information designed to be easily understood\n * by both humans and AI systems. Each error in the errors array provides\n * precise details about validation failures, including the exact path to the\n * problematic property, what type was expected, and what value was actually\n * provided.\n *\n * This detailed error structure is specifically optimized for AI function\n * calling validation feedback. When LLMs make type errors during function\n * calling, these granular error reports enable the AI to understand exactly\n * what went wrong and how to fix it, improving success rates in subsequent\n * attempts.\n *\n * Example error scenarios:\n *\n * - Type mismatch: expected "string" but got number 5\n * - Format violation: expected "string & Format<\'uuid\'>" but got\n * "invalid-format"\n * - Missing properties: expected "required property \'name\'" but got undefined\n * - Array type errors: expected "Array<string>" but got single string value\n *\n * The errors are used by ILlmFunction.validate() to provide structured\n * feedback to AI agents, enabling them to correct their parameter generation\n * and achieve improved function calling accuracy.\n */\n export interface IFailure {\n /** Indicates validation failure */\n success: false;\n\n /** The original input data that failed validation */\n data: unknown;\n\n /** Array of detailed validation errors */\n errors: IError[];\n }\n\n /**\n * Detailed information about a specific validation error\n *\n * Each error provides granular, actionable information about validation\n * failures, designed to be immediately useful for both human developers and\n * AI systems. The error structure follows a consistent format that enables\n * precise identification and correction of type mismatches.\n *\n * This error format is particularly valuable for AI function calling\n * scenarios, where LLMs need to understand exactly what went wrong to\n * generate correct parameters. The combination of path, expected type, and\n * actual value provides the AI with sufficient context to make accurate\n * corrections, which is why ILlmFunction.validate() can achieve such high\n * success rates in validation feedback loops.\n *\n * Real-world examples from AI function calling:\n *\n * {\n * path: "input.member.age",\n * expected: "number & Format<\'uint32\'>",\n * value: 20.75 // AI provided float instead of uint32\n * }\n *\n * {\n * path: "input.categories",\n * expected: "Array<string>",\n * value: "technology" // AI provided string instead of array\n * }\n *\n * {\n * path: "input.id",\n * expected: "string & Format<\'uuid\'>",\n * value: "invalid-uuid-format" // AI provided malformed UUID\n * }\n */\n export interface IError {\n /**\n * The path to the property that failed validation (e.g.,\n * "input.member.age")\n */\n path: string;\n\n /** Description of the expected type or format */\n expected: string;\n\n /** The actual value that caused the validation failure */\n value: any;\n }\n}\n````\n\nThe `IValidation.IFailure` object contains:\n\n- `success: false` - Indicates validation failed\n- `data: unknown` - The original invalid input data\n- `errors: IError[]` - Array of specific validation errors\n\nEach `IError` provides:\n\n- `path: string` - The property path that failed (e.g., "input.member.age")\n- `expected: string` - The required type/format description\n- `value: any` - The actual invalid value provided\n\n**Special case**: If `value` is `undefined`, it means the AI completely omitted that property from the parameters.\n\n## Response Format\n\nStructure your feedback as follows:\n\n```\n**Validation Failed - Please Fix the Following Issues:**\n\n**Error 1: [Path]**\n- **Problem**: [Describe what\'s wrong]\n- **Expected**: [Required type/format]\n- **Received**: [What was actually provided]\n- **Fix**: [Specific correction instructions]\n\n**Error 2: [Path]**\n- **Problem**: [Describe what\'s wrong]\n- **Expected**: [Required type/format]\n- **Received**: [What was actually provided]\n- **Fix**: [Specific correction instructions]\n\n**Corrected Parameters:**\n[Provide the complete corrected parameter structure]\n```\n\n## Common Error Scenarios\n\n1. **Type Mismatches**:\n\n - Expected string but got number\n - Expected array but got single value\n - Expected object but got primitive\n\n2. **Format Violations**:\n\n - Invalid UUID format\n - Invalid email format\n - Invalid date format\n\n3. **Missing Properties**:\n\n - Required properties omitted (value is undefined)\n - Nested object properties missing\n\n4. **Numeric Constraints**:\n\n - Expected integer but got float\n - Expected positive number but got negative\n - Expected specific numeric format (uint32, etc.)\n\n5. **Union Type Failures**:\n - None of the union variants match the provided value\n - Discriminator property missing or incorrect\n - Value doesn\'t conform to any of the possible types\n\n## Response Guidelines\n\n- **Be specific and actionable** - Don\'t just say "wrong type", explain exactly what needs to change\n- **Use clear language** - Avoid overly technical jargon\n- **Provide examples** - Show the correct format when it helps\n- **Be encouraging** - Frame feedback as guidance, not criticism\n- **Focus on solutions** - Emphasize how to fix rather than what went wrong\n\n### Special Handling for Union Types\n\nWhen you encounter an `expected` value with union syntax (e.g., `"A | B | C | D"`), this indicates a union type where none of the variants matched:\n\n1. **Check for Discriminator Property**:\n\n - Look for common properties that help identify which union variant was intended\n - Common discriminators: `type`, `kind`, `variant`, `action`, etc.\n - If a discriminator exists and matches one variant, focus your analysis on that specific type\n\n2. **With Discriminator Property**:\n\n ```\n **Error: Union Type Mismatch with Discriminator**\n - **Problem**: Value doesn\'t match the intended union variant\n - **Expected**: [Specific type based on discriminator]\n - **Discriminator**: [property]: "[value]" indicates [TypeName]\n - **Fix**: **COMPLETELY RECONSTRUCT** this value to properly match the [TypeName] structure. Analyze the [TypeName] requirements carefully and build a new value from scratch.\n ```\n\n3. **Without Discriminator Property**:\n ```\n **Error: Union Type Mismatch - Complete Reconstruction Required**\n - **Problem**: Value doesn\'t match any of the union variants\n - **Expected**: One of: A | B | C | D\n - **Received**: [current value]\n - **Fix**: **COMPLETELY REDESIGN** - This value needs to be rebuilt from scratch to match one of the union variants. Choose the most appropriate variant and construct a new value.\n ```\n\n## Example Response\n\n```\n**Validation Failed - Please Fix the Following Issues:**\n\n**Error 1: input.user.age**\n- **Problem**: Age must be a positive integer\n- **Expected**: number & Format<\'uint32\'>\n- **Received**: 25.5 (decimal number)\n- **Fix**: Change to a whole number like 25\n\n**Error 2: input.categories**\n- **Problem**: Categories should be an array of strings\n- **Expected**: Array<string>\n- **Received**: "technology" (single string)\n- **Fix**: Wrap in array: ["technology"]\n\n**Error 3: input.email**\n- **Problem**: Missing required email property\n- **Expected**: string & Format<\'email\'>\n- **Received**: undefined (property omitted)\n- **Fix**: Add email property with valid email format\n\n**Error 4: input.action**\n- **Problem**: Union type mismatch with discriminator\n- **Expected**: CreateUserAction | UpdateUserAction | DeleteUserAction\n- **Discriminator**: type: "create" indicates CreateUserAction\n- **Received**: { type: "create", name: "John" } (doesn\'t match CreateUserAction requirements)\n- **Fix**: **COMPLETELY RECONSTRUCT** for CreateUserAction. Analyze CreateUserAction schema carefully and build: { type: "create", name: "John", email: "john@example.com", role: "user" }\n\n**Error 5: input.payload**\n- **Problem**: Union type mismatch - complete reconstruction required\n- **Expected**: StringPayload | NumberPayload | ObjectPayload\n- **Received**: { data: "mixed", count: 5, flag: true } (doesn\'t match any variant)\n- **Fix**: **COMPLETELY REDESIGN** - Choose one variant and rebuild. For StringPayload: { data: "mixed" } OR for NumberPayload: { count: 5 } OR for ObjectPayload: { properties: { flag: true } }\n\n**Corrected Parameters:**\n{\n "user": {\n "age": 25\n },\n "categories": ["technology"],\n "email": "user@example.com",\n "action": {\n "type": "create",\n "name": "John",\n "email": "john@example.com",\n "role": "user"\n },\n "payload": {\n "data": "mixed"\n }\n}\n```\n\nYour goal is to help the AI understand exactly what went wrong and how to generate correct parameters on the next attempt.\n\n```\n\n```'
|
|
769
770
|
};
|
|
770
771
|
|
|
771
772
|
const getLocale = new Singleton((() => is_node() ? process.env.LANG?.split(".")[0] ?? "en-US" : navigator.language));
|
|
@@ -1348,7 +1349,7 @@ async function correct(ctx, call, retry, error) {
|
|
|
1348
1349
|
tool_call_id: call.id
|
|
1349
1350
|
}, {
|
|
1350
1351
|
role: "system",
|
|
1351
|
-
content:
|
|
1352
|
+
content: ctx.config?.systemPrompt?.validate?.() ?? AgenticaSystemPrompt.VALIDATE
|
|
1352
1353
|
} ],
|
|
1353
1354
|
tools: [ {
|
|
1354
1355
|
type: "function",
|
|
@@ -4156,7 +4157,24 @@ class Agentica {
|
|
|
4156
4157
|
}
|
|
4157
4158
|
});
|
|
4158
4159
|
props.dispatch(event);
|
|
4159
|
-
const
|
|
4160
|
+
const backoffStrategy = this.props.config?.backoffStrategy ?? (props => {
|
|
4161
|
+
throw props.error;
|
|
4162
|
+
});
|
|
4163
|
+
const completion = await (async () => {
|
|
4164
|
+
let count = 0;
|
|
4165
|
+
while (true) {
|
|
4166
|
+
try {
|
|
4167
|
+
return await this.props.vendor.api.chat.completions.create(event.body, event.options);
|
|
4168
|
+
} catch (error) {
|
|
4169
|
+
const waiting = backoffStrategy({
|
|
4170
|
+
count,
|
|
4171
|
+
error
|
|
4172
|
+
});
|
|
4173
|
+
await new Promise((resolve => setTimeout(resolve, waiting)));
|
|
4174
|
+
count++;
|
|
4175
|
+
}
|
|
4176
|
+
}
|
|
4177
|
+
})();
|
|
4160
4178
|
const [streamForEvent, temporaryStream] = StreamUtil.transform(completion.toReadableStream(), (value => ChatGptCompletionMessageUtil.transformCompletionChunk(value))).tee();
|
|
4161
4179
|
const [streamForAggregate, streamForReturn] = temporaryStream.tee();
|
|
4162
4180
|
(async () => {
|
|
@@ -43017,7 +43035,24 @@ class MicroAgentica {
|
|
|
43017
43035
|
options: this.props.vendor.options
|
|
43018
43036
|
});
|
|
43019
43037
|
props.dispatch(event);
|
|
43020
|
-
const
|
|
43038
|
+
const backoffStrategy = this.props.config?.backoffStrategy ?? (props => {
|
|
43039
|
+
throw props.error;
|
|
43040
|
+
});
|
|
43041
|
+
const completion = await (async () => {
|
|
43042
|
+
let count = 0;
|
|
43043
|
+
while (true) {
|
|
43044
|
+
try {
|
|
43045
|
+
return await this.props.vendor.api.chat.completions.create(event.body, event.options);
|
|
43046
|
+
} catch (error) {
|
|
43047
|
+
const waiting = backoffStrategy({
|
|
43048
|
+
count,
|
|
43049
|
+
error
|
|
43050
|
+
});
|
|
43051
|
+
await new Promise((resolve => setTimeout(resolve, waiting)));
|
|
43052
|
+
count++;
|
|
43053
|
+
}
|
|
43054
|
+
}
|
|
43055
|
+
})();
|
|
43021
43056
|
const [streamForEvent, temporaryStream] = StreamUtil.transform(completion.toReadableStream(), (value => ChatGptCompletionMessageUtil.transformCompletionChunk(value))).tee();
|
|
43022
43057
|
const [streamForAggregate, streamForReturn] = temporaryStream.tee();
|
|
43023
43058
|
void (async () => {
|