@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.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[];
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[];
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
- ## Function Call Instructions
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
- ## Output Formatting Rules
4729
- - Output must strictly follow the defined plaintext \`key: value\` field format.
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
- const task = [
4743
- `You will be provided with the following fields: ${inArgs}. Your task is to generate new fields: ${outArgs}.`
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(`## Available Functions
4764
+ task.push(`### Available Functions
4753
4765
  ${funcList}`);
4754
4766
  }
4755
4767
  const inputFields = this.renderFields(this.sig.getInputFields());
4756
- task.push(`## Input Fields
4768
+ task.push(`### Input Fields
4757
4769
  ${inputFields}`);
4758
4770
  const outputFields = this.renderFields(this.sig.getOutputFields());
4759
- task.push(`## Output Fields
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")
@@ -6057,23 +6061,23 @@ var AxAgent = class {
6057
6061
  disableSmartModelRouting;
6058
6062
  excludeFieldsFromPassthrough;
6059
6063
  name;
6060
- subAgentList;
6064
+ // private subAgentList?: string
6061
6065
  func;
6062
6066
  constructor({
6063
6067
  ai,
6064
6068
  name,
6065
6069
  description,
6070
+ definition,
6066
6071
  signature,
6067
6072
  agents,
6068
6073
  functions
6069
6074
  }, options) {
6075
+ const { disableSmartModelRouting, excludeFieldsFromPassthrough } = options ?? {};
6070
6076
  this.ai = ai;
6071
6077
  this.agents = agents;
6072
6078
  this.functions = functions;
6073
- this.disableSmartModelRouting = options?.disableSmartModelRouting;
6074
- this.excludeFieldsFromPassthrough = options?.excludeFieldsFromPassthrough ?? [];
6075
- const sig = new AxSignature(signature);
6076
- sig.setDescription(description);
6079
+ this.disableSmartModelRouting = disableSmartModelRouting;
6080
+ this.excludeFieldsFromPassthrough = excludeFieldsFromPassthrough ?? [];
6077
6081
  if (!name || name.length < 5) {
6078
6082
  throw new Error(
6079
6083
  `Agent name must be at least 10 characters (more descriptive): ${name}`
@@ -6084,16 +6088,23 @@ var AxAgent = class {
6084
6088
  `Agent description must be at least 20 characters (explain in detail what the agent does): ${description}`
6085
6089
  );
6086
6090
  }
6087
- this.program = new AxGen(sig, options);
6091
+ if (definition && definition.length < 100) {
6092
+ throw new Error(
6093
+ `Agent definition is the prompt you give to the LLM for the agent. It must be detailed and at least 100 characters`
6094
+ );
6095
+ }
6096
+ this.program = new AxGen(signature, {
6097
+ ...options,
6098
+ description: definition
6099
+ });
6088
6100
  for (const agent of agents ?? []) {
6089
6101
  this.program.register(agent);
6090
6102
  }
6091
6103
  this.name = name;
6092
- this.subAgentList = agents?.map((a) => a.getFunction().name).join(", ");
6093
6104
  this.func = {
6094
6105
  name: toCamelCase(this.name),
6095
6106
  description,
6096
- parameters: sig.toJSONSchema(),
6107
+ parameters: this.program.getSignature().toJSONSchema(),
6097
6108
  func: () => this.forward
6098
6109
  };
6099
6110
  const mm = ai?.getModelList();
@@ -6124,13 +6135,26 @@ var AxAgent = class {
6124
6135
  }
6125
6136
  getFunction() {
6126
6137
  const boundFunc = this.forward.bind(this);
6127
- const wrappedFunc = (valuesAndModel, options) => {
6138
+ const wrappedFunc = async (valuesAndModel, options) => {
6128
6139
  const { model, ...values } = valuesAndModel;
6129
6140
  const ai = this.ai ?? options?.ai;
6130
6141
  if (!ai) {
6131
6142
  throw new Error("AI service is required to run the agent");
6132
6143
  }
6133
- return boundFunc(ai, values, { ...options, model });
6144
+ const ret = await boundFunc(ai, values, {
6145
+ ...options,
6146
+ model
6147
+ });
6148
+ const sig = this.program.getSignature();
6149
+ const outFields = sig.getOutputFields();
6150
+ const result = Object.keys(ret).map((k) => {
6151
+ const field = outFields.find((f) => f.name === k);
6152
+ if (field) {
6153
+ return `${field.title}: ${ret[k]}`;
6154
+ }
6155
+ return `${k}: ${ret[k]}`;
6156
+ }).join("\n");
6157
+ return result;
6134
6158
  };
6135
6159
  return {
6136
6160
  ...this.func,