@ax-llm/ax 11.0.5 → 11.0.7

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
@@ -5919,8 +5919,8 @@ var AxGen = class extends AxProgramWithSignature {
5919
5919
  }) {
5920
5920
  const values = {};
5921
5921
  let results = res.results ?? [];
5922
- if (res.results.length > 1) {
5923
- results = res.results.filter((r) => r.functionCalls);
5922
+ if (results.length > 1) {
5923
+ results = results.filter((r) => r.functionCalls);
5924
5924
  }
5925
5925
  for (const result of results) {
5926
5926
  if (res.modelUsage) {
@@ -6089,6 +6089,37 @@ var AxGen = class extends AxProgramWithSignature {
6089
6089
  };
6090
6090
 
6091
6091
  // prompts/agent.ts
6092
+ function processChildAgentFunction(childFunction, parentValues, parentInputKeys, modelList, options) {
6093
+ let processedFunction = { ...childFunction };
6094
+ if (processedFunction.parameters) {
6095
+ const childKeys = processedFunction.parameters.properties ? Object.keys(processedFunction.parameters.properties) : [];
6096
+ const commonKeys = parentInputKeys.filter((key) => childKeys.includes(key)).filter((key) => key !== "model");
6097
+ const injectionKeys = commonKeys.filter(
6098
+ (key) => !options.excludeFieldsFromPassthrough.includes(key)
6099
+ );
6100
+ if (injectionKeys.length > 0) {
6101
+ processedFunction.parameters = removePropertiesFromSchema(
6102
+ processedFunction.parameters,
6103
+ injectionKeys
6104
+ );
6105
+ const originalFunc = processedFunction.func;
6106
+ processedFunction.func = (childArgs, funcOptions) => originalFunc(
6107
+ {
6108
+ ...childArgs,
6109
+ ...pick(parentValues, injectionKeys)
6110
+ },
6111
+ funcOptions
6112
+ );
6113
+ }
6114
+ }
6115
+ if (modelList && !options.disableSmartModelRouting && options.canConfigureSmartModelRouting) {
6116
+ processedFunction.parameters = addModelParameter(
6117
+ processedFunction.parameters,
6118
+ modelList
6119
+ );
6120
+ }
6121
+ return processedFunction;
6122
+ }
6092
6123
  var AxAgent = class {
6093
6124
  ai;
6094
6125
  signature;
@@ -6096,6 +6127,7 @@ var AxAgent = class {
6096
6127
  functions;
6097
6128
  agents;
6098
6129
  disableSmartModelRouting;
6130
+ excludeFieldsFromPassthrough;
6099
6131
  name;
6100
6132
  description;
6101
6133
  subAgentList;
@@ -6112,6 +6144,7 @@ var AxAgent = class {
6112
6144
  this.agents = agents;
6113
6145
  this.functions = functions;
6114
6146
  this.disableSmartModelRouting = options?.disableSmartModelRouting;
6147
+ this.excludeFieldsFromPassthrough = options?.excludeFieldsFromPassthrough ?? [];
6115
6148
  this.signature = new AxSignature(signature);
6116
6149
  this.signature.setDescription(description);
6117
6150
  if (!name || name.length < 5) {
@@ -6180,15 +6213,33 @@ var AxAgent = class {
6180
6213
  }
6181
6214
  getFeatures() {
6182
6215
  return {
6183
- canConfigureSmartModelRouting: this.ai !== void 0
6216
+ canConfigureSmartModelRouting: this.ai === void 0,
6217
+ excludeFieldsFromPassthrough: this.excludeFieldsFromPassthrough
6184
6218
  };
6185
6219
  }
6186
- init(parentAi, options) {
6220
+ /**
6221
+ * Initializes the agent's execution context, processing child agents and their functions.
6222
+ */
6223
+ init(parentAi, values, options) {
6187
6224
  const ai = this.ai ?? parentAi;
6188
6225
  const mm = ai?.getModelList();
6189
- const agentFuncs = this.agents?.map((a) => a.getFunction())?.map(
6190
- (f) => mm && !this.disableSmartModelRouting && this.agents?.find((a) => a.getFunction().name === f.name)?.getFeatures().canConfigureSmartModelRouting ? { ...f, parameters: addModelParameter(f.parameters, mm) } : f
6191
- );
6226
+ const parentSchema = this.signature.toJSONSchema();
6227
+ const parentKeys = parentSchema.properties ? Object.keys(parentSchema.properties) : [];
6228
+ const agentFuncs = this.agents?.map((agent) => {
6229
+ const f = agent.getFeatures();
6230
+ const processOptions = {
6231
+ disableSmartModelRouting: !!this.disableSmartModelRouting,
6232
+ excludeFieldsFromPassthrough: f.excludeFieldsFromPassthrough,
6233
+ canConfigureSmartModelRouting: f.canConfigureSmartModelRouting
6234
+ };
6235
+ return processChildAgentFunction(
6236
+ agent.getFunction(),
6237
+ values,
6238
+ parentKeys,
6239
+ mm,
6240
+ processOptions
6241
+ );
6242
+ });
6192
6243
  const functions = [
6193
6244
  ...options?.functions ?? this.functions ?? [],
6194
6245
  ...agentFuncs ?? []
@@ -6196,16 +6247,33 @@ var AxAgent = class {
6196
6247
  return { ai, functions };
6197
6248
  }
6198
6249
  async forward(parentAi, values, options) {
6199
- const { ai, functions } = this.init(parentAi, options);
6250
+ const { ai, functions } = this.init(parentAi, values, options);
6200
6251
  return await this.program.forward(ai, values, { ...options, functions });
6201
6252
  }
6202
6253
  async *streamingForward(parentAi, values, options) {
6203
- const { ai, functions } = this.init(parentAi, options);
6254
+ const { ai, functions } = this.init(parentAi, values, options);
6204
6255
  return yield* this.program.streamingForward(ai, values, {
6205
6256
  ...options,
6206
6257
  functions
6207
6258
  });
6208
6259
  }
6260
+ /**
6261
+ * Updates the agent's description.
6262
+ * This updates both the stored description and the function's description.
6263
+ *
6264
+ * @param description - New description for the agent (must be at least 20 characters)
6265
+ * @throws Error if description is too short
6266
+ */
6267
+ setDescription(description) {
6268
+ if (!description || description.length < 20) {
6269
+ throw new Error(
6270
+ "Agent description must be at least 20 characters (explain in detail what the agent does)"
6271
+ );
6272
+ }
6273
+ this.description = description;
6274
+ this.signature.setDescription(description);
6275
+ this.func.description = description;
6276
+ }
6209
6277
  };
6210
6278
  function toCamelCase(inputString) {
6211
6279
  const words = inputString.split(/[^a-zA-Z0-9]/);
@@ -6243,6 +6311,34 @@ function addModelParameter(parameters, models) {
6243
6311
  required: newRequired
6244
6312
  };
6245
6313
  }
6314
+ function removePropertiesFromSchema(schema, keys) {
6315
+ const newSchema = structuredClone(schema);
6316
+ if (newSchema.properties) {
6317
+ for (const key of keys) {
6318
+ delete newSchema.properties[key];
6319
+ }
6320
+ }
6321
+ if (Array.isArray(newSchema.required)) {
6322
+ const filteredRequired = newSchema.required.filter(
6323
+ (r) => !keys.includes(r)
6324
+ );
6325
+ Object.defineProperty(newSchema, "required", {
6326
+ value: filteredRequired,
6327
+ writable: true,
6328
+ configurable: true
6329
+ });
6330
+ }
6331
+ return newSchema;
6332
+ }
6333
+ function pick(obj, keys) {
6334
+ const result = {};
6335
+ for (const key of keys) {
6336
+ if (key in obj) {
6337
+ result[key] = obj[key];
6338
+ }
6339
+ }
6340
+ return result;
6341
+ }
6246
6342
 
6247
6343
  // docs/tika.ts
6248
6344
  var import_node_fs = require("fs");