@ax-llm/ax 11.0.9 → 11.0.12
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/index.cjs +65 -35
- package/index.cjs.map +1 -1
- package/index.d.cts +3 -2
- package/index.d.ts +3 -2
- package/index.js +65 -35
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.d.cts
CHANGED
|
@@ -1644,12 +1644,12 @@ declare class AxAgent<IN extends AxGenIn, OUT extends AxGenOut = AxGenOut> imple
|
|
|
1644
1644
|
private disableSmartModelRouting?;
|
|
1645
1645
|
private excludeFieldsFromPassthrough;
|
|
1646
1646
|
private name;
|
|
1647
|
-
private subAgentList?;
|
|
1648
1647
|
private func;
|
|
1649
|
-
constructor({ ai, name, description, signature, agents, functions, }: Readonly<{
|
|
1648
|
+
constructor({ ai, name, description, definition, signature, agents, functions, }: Readonly<{
|
|
1650
1649
|
ai?: Readonly<AxAIService>;
|
|
1651
1650
|
name: string;
|
|
1652
1651
|
description: string;
|
|
1652
|
+
definition?: string;
|
|
1653
1653
|
signature: AxSignature | string;
|
|
1654
1654
|
agents?: AxAgentic[];
|
|
1655
1655
|
functions?: AxFunction[];
|
|
@@ -1680,6 +1680,7 @@ declare class AxAgent<IN extends AxGenIn, OUT extends AxGenOut = AxGenOut> imple
|
|
|
1680
1680
|
* @throws Error if description is too short
|
|
1681
1681
|
*/
|
|
1682
1682
|
setDescription(description: string): void;
|
|
1683
|
+
setDefinition(definition: string): void;
|
|
1683
1684
|
}
|
|
1684
1685
|
|
|
1685
1686
|
interface AxApacheTikaArgs {
|
package/index.d.ts
CHANGED
|
@@ -1644,12 +1644,12 @@ declare class AxAgent<IN extends AxGenIn, OUT extends AxGenOut = AxGenOut> imple
|
|
|
1644
1644
|
private disableSmartModelRouting?;
|
|
1645
1645
|
private excludeFieldsFromPassthrough;
|
|
1646
1646
|
private name;
|
|
1647
|
-
private subAgentList?;
|
|
1648
1647
|
private func;
|
|
1649
|
-
constructor({ ai, name, description, signature, agents, functions, }: Readonly<{
|
|
1648
|
+
constructor({ ai, name, description, definition, signature, agents, functions, }: Readonly<{
|
|
1650
1649
|
ai?: Readonly<AxAIService>;
|
|
1651
1650
|
name: string;
|
|
1652
1651
|
description: string;
|
|
1652
|
+
definition?: string;
|
|
1653
1653
|
signature: AxSignature | string;
|
|
1654
1654
|
agents?: AxAgentic[];
|
|
1655
1655
|
functions?: AxFunction[];
|
|
@@ -1680,6 +1680,7 @@ declare class AxAgent<IN extends AxGenIn, OUT extends AxGenOut = AxGenOut> imple
|
|
|
1680
1680
|
* @throws Error if description is too short
|
|
1681
1681
|
*/
|
|
1682
1682
|
setDescription(description: string): void;
|
|
1683
|
+
setDefinition(definition: string): void;
|
|
1683
1684
|
}
|
|
1684
1685
|
|
|
1685
1686
|
interface AxApacheTikaArgs {
|
package/index.js
CHANGED
|
@@ -1048,7 +1048,11 @@ var AxBaseAI = class {
|
|
|
1048
1048
|
}
|
|
1049
1049
|
};
|
|
1050
1050
|
var logChatRequest = (req) => {
|
|
1051
|
+
const hasAssistant = req.chatPrompt?.some((msg) => msg.role === "assistant");
|
|
1051
1052
|
const items = req.chatPrompt?.map((msg) => {
|
|
1053
|
+
if (hasAssistant && msg.role === "system") {
|
|
1054
|
+
return "";
|
|
1055
|
+
}
|
|
1052
1056
|
switch (msg.role) {
|
|
1053
1057
|
case "system":
|
|
1054
1058
|
return `${colorLog.blueBright("System:")}
|
|
@@ -4720,16 +4724,17 @@ var AxProgram = class {
|
|
|
4720
4724
|
|
|
4721
4725
|
// dsp/prompt.ts
|
|
4722
4726
|
var functionCallInstructions = `
|
|
4723
|
-
|
|
4727
|
+
### Function Call Instructions
|
|
4724
4728
|
- Complete the task, using the functions defined earlier in this prompt.
|
|
4725
4729
|
- Call functions step-by-step, using the output of one function as input to the next.
|
|
4726
4730
|
- Use the function results to generate the output fields.`;
|
|
4727
4731
|
var formattingRules = `
|
|
4728
|
-
|
|
4729
|
-
- Output must strictly follow the defined
|
|
4732
|
+
### Output Formatting Rules
|
|
4733
|
+
- Output must strictly follow the defined plain-text \`key: value\` field format.
|
|
4730
4734
|
- Each output key, value must strictly adhere to the specified output field formatting rules.
|
|
4731
4735
|
- No preamble, postscript, or supplementary information.
|
|
4732
|
-
- Do not repeat output fields
|
|
4736
|
+
- Do not repeat output fields.
|
|
4737
|
+
- Do not use JSON to format the output.`;
|
|
4733
4738
|
var AxPromptTemplate = class {
|
|
4734
4739
|
sig;
|
|
4735
4740
|
fieldTemplates;
|
|
@@ -4737,11 +4742,18 @@ var AxPromptTemplate = class {
|
|
|
4737
4742
|
constructor(sig, functions, fieldTemplates) {
|
|
4738
4743
|
this.sig = sig;
|
|
4739
4744
|
this.fieldTemplates = fieldTemplates;
|
|
4745
|
+
const task = [];
|
|
4746
|
+
const desc = this.sig.getDescription();
|
|
4747
|
+
if (desc) {
|
|
4748
|
+
const capitalized = capitalizeFirstLetter(desc.trim());
|
|
4749
|
+
task.push(capitalized.endsWith(".") ? capitalized : capitalized + ".");
|
|
4750
|
+
}
|
|
4740
4751
|
const inArgs = this.renderDescFields(this.sig.getInputFields());
|
|
4741
4752
|
const outArgs = this.renderDescFields(this.sig.getOutputFields());
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4753
|
+
task.push(
|
|
4754
|
+
`## Processing Instructions
|
|
4755
|
+
You will be provided with the following fields: ${inArgs}. Your task is to generate new fields: ${outArgs}.`
|
|
4756
|
+
);
|
|
4745
4757
|
const funcs = functions?.map(
|
|
4746
4758
|
(f) => "toFunction" in f ? f.toFunction() : f
|
|
4747
4759
|
);
|
|
@@ -4749,27 +4761,19 @@ var AxPromptTemplate = class {
|
|
|
4749
4761
|
(fn) => `- \`${fn.name}\`: ${capitalizeFirstLetter(fn.description)}.`
|
|
4750
4762
|
).join("\n");
|
|
4751
4763
|
if (funcList && funcList.length > 0) {
|
|
4752
|
-
task.push(
|
|
4764
|
+
task.push(`### Available Functions
|
|
4753
4765
|
${funcList}`);
|
|
4754
4766
|
}
|
|
4755
4767
|
const inputFields = this.renderFields(this.sig.getInputFields());
|
|
4756
|
-
task.push(
|
|
4768
|
+
task.push(`### Input Fields
|
|
4757
4769
|
${inputFields}`);
|
|
4758
4770
|
const outputFields = this.renderFields(this.sig.getOutputFields());
|
|
4759
|
-
task.push(
|
|
4771
|
+
task.push(`### Output Fields
|
|
4760
4772
|
${outputFields}`);
|
|
4761
4773
|
if (funcList && funcList.length > 0) {
|
|
4762
4774
|
task.push(functionCallInstructions.trim());
|
|
4763
4775
|
}
|
|
4764
4776
|
task.push(formattingRules.trim());
|
|
4765
|
-
const desc = this.sig.getDescription();
|
|
4766
|
-
if (desc) {
|
|
4767
|
-
const capitalized = capitalizeFirstLetter(desc.trim());
|
|
4768
|
-
task.push(
|
|
4769
|
-
`## TASK DESCRIPTION
|
|
4770
|
-
${capitalized.endsWith(".") ? capitalized : capitalized + "."}`
|
|
4771
|
-
);
|
|
4772
|
-
}
|
|
4773
4777
|
this.task = {
|
|
4774
4778
|
type: "text",
|
|
4775
4779
|
text: task.join("\n\n")
|
|
@@ -6049,6 +6053,12 @@ function processChildAgentFunction(childFunction, parentValues, parentInputKeys,
|
|
|
6049
6053
|
}
|
|
6050
6054
|
return processedFunction;
|
|
6051
6055
|
}
|
|
6056
|
+
var descriptionError = new Error(
|
|
6057
|
+
"Agent description must be at least 20 characters (explain in detail what the agent does)"
|
|
6058
|
+
);
|
|
6059
|
+
var definitionError = new Error(
|
|
6060
|
+
"Agent definition is the prompt you give to the LLM for the agent. It must be detailed and at least 100 characters"
|
|
6061
|
+
);
|
|
6052
6062
|
var AxAgent = class {
|
|
6053
6063
|
ai;
|
|
6054
6064
|
program;
|
|
@@ -6057,43 +6067,46 @@ var AxAgent = class {
|
|
|
6057
6067
|
disableSmartModelRouting;
|
|
6058
6068
|
excludeFieldsFromPassthrough;
|
|
6059
6069
|
name;
|
|
6060
|
-
subAgentList
|
|
6070
|
+
// private subAgentList?: string
|
|
6061
6071
|
func;
|
|
6062
6072
|
constructor({
|
|
6063
6073
|
ai,
|
|
6064
6074
|
name,
|
|
6065
6075
|
description,
|
|
6076
|
+
definition,
|
|
6066
6077
|
signature,
|
|
6067
6078
|
agents,
|
|
6068
6079
|
functions
|
|
6069
6080
|
}, options) {
|
|
6081
|
+
const { disableSmartModelRouting, excludeFieldsFromPassthrough } = options ?? {};
|
|
6070
6082
|
this.ai = ai;
|
|
6071
6083
|
this.agents = agents;
|
|
6072
6084
|
this.functions = functions;
|
|
6073
|
-
this.disableSmartModelRouting =
|
|
6074
|
-
this.excludeFieldsFromPassthrough =
|
|
6075
|
-
const sig = new AxSignature(signature);
|
|
6076
|
-
sig.setDescription(description);
|
|
6085
|
+
this.disableSmartModelRouting = disableSmartModelRouting;
|
|
6086
|
+
this.excludeFieldsFromPassthrough = excludeFieldsFromPassthrough ?? [];
|
|
6077
6087
|
if (!name || name.length < 5) {
|
|
6078
6088
|
throw new Error(
|
|
6079
|
-
`Agent name must be at least 10 characters (more descriptive)
|
|
6089
|
+
`Agent name must be at least 10 characters (more descriptive)`
|
|
6080
6090
|
);
|
|
6081
6091
|
}
|
|
6082
6092
|
if (!description || description.length < 20) {
|
|
6083
|
-
throw
|
|
6084
|
-
|
|
6085
|
-
|
|
6093
|
+
throw descriptionError;
|
|
6094
|
+
}
|
|
6095
|
+
if (definition && definition.length < 100) {
|
|
6096
|
+
throw definitionError;
|
|
6086
6097
|
}
|
|
6087
|
-
this.program = new AxGen(
|
|
6098
|
+
this.program = new AxGen(signature, {
|
|
6099
|
+
...options,
|
|
6100
|
+
description: definition ?? description
|
|
6101
|
+
});
|
|
6088
6102
|
for (const agent of agents ?? []) {
|
|
6089
6103
|
this.program.register(agent);
|
|
6090
6104
|
}
|
|
6091
6105
|
this.name = name;
|
|
6092
|
-
this.subAgentList = agents?.map((a) => a.getFunction().name).join(", ");
|
|
6093
6106
|
this.func = {
|
|
6094
6107
|
name: toCamelCase(this.name),
|
|
6095
6108
|
description,
|
|
6096
|
-
parameters:
|
|
6109
|
+
parameters: this.program.getSignature().toJSONSchema(),
|
|
6097
6110
|
func: () => this.forward
|
|
6098
6111
|
};
|
|
6099
6112
|
const mm = ai?.getModelList();
|
|
@@ -6124,13 +6137,26 @@ var AxAgent = class {
|
|
|
6124
6137
|
}
|
|
6125
6138
|
getFunction() {
|
|
6126
6139
|
const boundFunc = this.forward.bind(this);
|
|
6127
|
-
const wrappedFunc = (valuesAndModel, options) => {
|
|
6140
|
+
const wrappedFunc = async (valuesAndModel, options) => {
|
|
6128
6141
|
const { model, ...values } = valuesAndModel;
|
|
6129
6142
|
const ai = this.ai ?? options?.ai;
|
|
6130
6143
|
if (!ai) {
|
|
6131
6144
|
throw new Error("AI service is required to run the agent");
|
|
6132
6145
|
}
|
|
6133
|
-
|
|
6146
|
+
const ret = await boundFunc(ai, values, {
|
|
6147
|
+
...options,
|
|
6148
|
+
model
|
|
6149
|
+
});
|
|
6150
|
+
const sig = this.program.getSignature();
|
|
6151
|
+
const outFields = sig.getOutputFields();
|
|
6152
|
+
const result = Object.keys(ret).map((k) => {
|
|
6153
|
+
const field = outFields.find((f) => f.name === k);
|
|
6154
|
+
if (field) {
|
|
6155
|
+
return `${field.title}: ${ret[k]}`;
|
|
6156
|
+
}
|
|
6157
|
+
return `${k}: ${ret[k]}`;
|
|
6158
|
+
}).join("\n");
|
|
6159
|
+
return result;
|
|
6134
6160
|
};
|
|
6135
6161
|
return {
|
|
6136
6162
|
...this.func,
|
|
@@ -6193,13 +6219,17 @@ var AxAgent = class {
|
|
|
6193
6219
|
*/
|
|
6194
6220
|
setDescription(description) {
|
|
6195
6221
|
if (!description || description.length < 20) {
|
|
6196
|
-
throw
|
|
6197
|
-
"Agent description must be at least 20 characters (explain in detail what the agent does)"
|
|
6198
|
-
);
|
|
6222
|
+
throw descriptionError;
|
|
6199
6223
|
}
|
|
6200
6224
|
this.program.getSignature().setDescription(description);
|
|
6201
6225
|
this.func.description = description;
|
|
6202
6226
|
}
|
|
6227
|
+
setDefinition(definition) {
|
|
6228
|
+
if (!definition || definition.length < 100) {
|
|
6229
|
+
throw definitionError;
|
|
6230
|
+
}
|
|
6231
|
+
this.program.getSignature().setDescription(definition);
|
|
6232
|
+
}
|
|
6203
6233
|
};
|
|
6204
6234
|
function toCamelCase(inputString) {
|
|
6205
6235
|
const words = inputString.split(/[^a-zA-Z0-9]/);
|