@ax-llm/ax 11.0.9 → 11.0.11

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 CHANGED
@@ -1150,7 +1150,11 @@ var AxBaseAI = class {
1150
1150
  }
1151
1151
  };
1152
1152
  var logChatRequest = (req) => {
1153
+ const hasAssistant = req.chatPrompt?.some((msg) => msg.role === "assistant");
1153
1154
  const items = req.chatPrompt?.map((msg) => {
1155
+ if (hasAssistant && msg.role === "system") {
1156
+ return "";
1157
+ }
1154
1158
  switch (msg.role) {
1155
1159
  case "system":
1156
1160
  return `${colorLog.blueBright("System:")}
@@ -4822,16 +4826,17 @@ var AxProgram = class {
4822
4826
 
4823
4827
  // dsp/prompt.ts
4824
4828
  var functionCallInstructions = `
4825
- ## Function Call Instructions
4829
+ ### Function Call Instructions
4826
4830
  - Complete the task, using the functions defined earlier in this prompt.
4827
4831
  - Call functions step-by-step, using the output of one function as input to the next.
4828
4832
  - Use the function results to generate the output fields.`;
4829
4833
  var formattingRules = `
4830
- ## Output Formatting Rules
4831
- - Output must strictly follow the defined plaintext \`key: value\` field format.
4834
+ ### Output Formatting Rules
4835
+ - Output must strictly follow the defined plain-text \`key: value\` field format.
4832
4836
  - Each output key, value must strictly adhere to the specified output field formatting rules.
4833
4837
  - No preamble, postscript, or supplementary information.
4834
- - Do not repeat output fields.`;
4838
+ - Do not repeat output fields.
4839
+ - Do not use JSON to format the output.`;
4835
4840
  var AxPromptTemplate = class {
4836
4841
  sig;
4837
4842
  fieldTemplates;
@@ -4839,11 +4844,18 @@ var AxPromptTemplate = class {
4839
4844
  constructor(sig, functions, fieldTemplates) {
4840
4845
  this.sig = sig;
4841
4846
  this.fieldTemplates = fieldTemplates;
4847
+ const task = [];
4848
+ const desc = this.sig.getDescription();
4849
+ if (desc) {
4850
+ const capitalized = capitalizeFirstLetter(desc.trim());
4851
+ task.push(capitalized.endsWith(".") ? capitalized : capitalized + ".");
4852
+ }
4842
4853
  const inArgs = this.renderDescFields(this.sig.getInputFields());
4843
4854
  const outArgs = this.renderDescFields(this.sig.getOutputFields());
4844
- const task = [
4845
- `You will be provided with the following fields: ${inArgs}. Your task is to generate new fields: ${outArgs}.`
4846
- ];
4855
+ task.push(
4856
+ `## Processing Instructions
4857
+ You will be provided with the following fields: ${inArgs}. Your task is to generate new fields: ${outArgs}.`
4858
+ );
4847
4859
  const funcs = functions?.map(
4848
4860
  (f) => "toFunction" in f ? f.toFunction() : f
4849
4861
  );
@@ -4851,27 +4863,19 @@ var AxPromptTemplate = class {
4851
4863
  (fn) => `- \`${fn.name}\`: ${capitalizeFirstLetter(fn.description)}.`
4852
4864
  ).join("\n");
4853
4865
  if (funcList && funcList.length > 0) {
4854
- task.push(`## Available Functions
4866
+ task.push(`### Available Functions
4855
4867
  ${funcList}`);
4856
4868
  }
4857
4869
  const inputFields = this.renderFields(this.sig.getInputFields());
4858
- task.push(`## Input Fields
4870
+ task.push(`### Input Fields
4859
4871
  ${inputFields}`);
4860
4872
  const outputFields = this.renderFields(this.sig.getOutputFields());
4861
- task.push(`## Output Fields
4873
+ task.push(`### Output Fields
4862
4874
  ${outputFields}`);
4863
4875
  if (funcList && funcList.length > 0) {
4864
4876
  task.push(functionCallInstructions.trim());
4865
4877
  }
4866
4878
  task.push(formattingRules.trim());
4867
- const desc = this.sig.getDescription();
4868
- if (desc) {
4869
- const capitalized = capitalizeFirstLetter(desc.trim());
4870
- task.push(
4871
- `## TASK DESCRIPTION
4872
- ${capitalized.endsWith(".") ? capitalized : capitalized + "."}`
4873
- );
4874
- }
4875
4879
  this.task = {
4876
4880
  type: "text",
4877
4881
  text: task.join("\n\n")
@@ -6159,23 +6163,23 @@ var AxAgent = class {
6159
6163
  disableSmartModelRouting;
6160
6164
  excludeFieldsFromPassthrough;
6161
6165
  name;
6162
- subAgentList;
6166
+ // private subAgentList?: string
6163
6167
  func;
6164
6168
  constructor({
6165
6169
  ai,
6166
6170
  name,
6167
6171
  description,
6172
+ definition,
6168
6173
  signature,
6169
6174
  agents,
6170
6175
  functions
6171
6176
  }, options) {
6177
+ const { disableSmartModelRouting, excludeFieldsFromPassthrough } = options ?? {};
6172
6178
  this.ai = ai;
6173
6179
  this.agents = agents;
6174
6180
  this.functions = functions;
6175
- this.disableSmartModelRouting = options?.disableSmartModelRouting;
6176
- this.excludeFieldsFromPassthrough = options?.excludeFieldsFromPassthrough ?? [];
6177
- const sig = new AxSignature(signature);
6178
- sig.setDescription(description);
6181
+ this.disableSmartModelRouting = disableSmartModelRouting;
6182
+ this.excludeFieldsFromPassthrough = excludeFieldsFromPassthrough ?? [];
6179
6183
  if (!name || name.length < 5) {
6180
6184
  throw new Error(
6181
6185
  `Agent name must be at least 10 characters (more descriptive): ${name}`
@@ -6186,16 +6190,23 @@ var AxAgent = class {
6186
6190
  `Agent description must be at least 20 characters (explain in detail what the agent does): ${description}`
6187
6191
  );
6188
6192
  }
6189
- this.program = new AxGen(sig, options);
6193
+ if (definition && definition.length < 100) {
6194
+ throw new Error(
6195
+ `Agent definition is the prompt you give to the LLM for the agent. It must be detailed and at least 100 characters`
6196
+ );
6197
+ }
6198
+ this.program = new AxGen(signature, {
6199
+ ...options,
6200
+ description: definition
6201
+ });
6190
6202
  for (const agent of agents ?? []) {
6191
6203
  this.program.register(agent);
6192
6204
  }
6193
6205
  this.name = name;
6194
- this.subAgentList = agents?.map((a) => a.getFunction().name).join(", ");
6195
6206
  this.func = {
6196
6207
  name: toCamelCase(this.name),
6197
6208
  description,
6198
- parameters: sig.toJSONSchema(),
6209
+ parameters: this.program.getSignature().toJSONSchema(),
6199
6210
  func: () => this.forward
6200
6211
  };
6201
6212
  const mm = ai?.getModelList();
@@ -6226,13 +6237,26 @@ var AxAgent = class {
6226
6237
  }
6227
6238
  getFunction() {
6228
6239
  const boundFunc = this.forward.bind(this);
6229
- const wrappedFunc = (valuesAndModel, options) => {
6240
+ const wrappedFunc = async (valuesAndModel, options) => {
6230
6241
  const { model, ...values } = valuesAndModel;
6231
6242
  const ai = this.ai ?? options?.ai;
6232
6243
  if (!ai) {
6233
6244
  throw new Error("AI service is required to run the agent");
6234
6245
  }
6235
- return boundFunc(ai, values, { ...options, model });
6246
+ const ret = await boundFunc(ai, values, {
6247
+ ...options,
6248
+ model
6249
+ });
6250
+ const sig = this.program.getSignature();
6251
+ const outFields = sig.getOutputFields();
6252
+ const result = Object.keys(ret).map((k) => {
6253
+ const field = outFields.find((f) => f.name === k);
6254
+ if (field) {
6255
+ return `${field.title}: ${ret[k]}`;
6256
+ }
6257
+ return `${k}: ${ret[k]}`;
6258
+ }).join("\n");
6259
+ return result;
6236
6260
  };
6237
6261
  return {
6238
6262
  ...this.func,