@ax-llm/ax 11.0.6 → 11.0.8
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 +118 -9
- package/index.cjs.map +1 -1
- package/index.d.cts +25 -0
- package/index.d.ts +25 -0
- package/index.js +118 -9
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.d.cts
CHANGED
|
@@ -1612,16 +1612,29 @@ declare class AxGen<IN extends AxGenIn = AxGenIn, OUT extends AxGenerateResult<A
|
|
|
1612
1612
|
}, void, unknown>;
|
|
1613
1613
|
}
|
|
1614
1614
|
|
|
1615
|
+
/**
|
|
1616
|
+
* Interface for agents that can be used as child agents.
|
|
1617
|
+
* Provides methods to get the agent's function definition and features.
|
|
1618
|
+
*/
|
|
1615
1619
|
interface AxAgentic extends AxTunable, AxUsable {
|
|
1616
1620
|
getFunction(): AxFunction;
|
|
1617
1621
|
getFeatures(): AxAgentFeatures;
|
|
1618
1622
|
}
|
|
1619
1623
|
type AxAgentOptions = Omit<AxGenOptions, 'functions'> & {
|
|
1620
1624
|
disableSmartModelRouting?: boolean;
|
|
1625
|
+
/** List of field names that should not be automatically passed from parent to child agents */
|
|
1626
|
+
excludeFieldsFromPassthrough?: string[];
|
|
1621
1627
|
};
|
|
1622
1628
|
interface AxAgentFeatures {
|
|
1629
|
+
/** Whether this agent can use smart model routing (requires an AI service) */
|
|
1623
1630
|
canConfigureSmartModelRouting: boolean;
|
|
1631
|
+
/** List of fields that this agent excludes from parent->child value passing */
|
|
1632
|
+
excludeFieldsFromPassthrough: string[];
|
|
1624
1633
|
}
|
|
1634
|
+
/**
|
|
1635
|
+
* An AI agent that can process inputs using an AI service and coordinate with child agents.
|
|
1636
|
+
* Supports features like smart model routing and automatic input field passing to child agents.
|
|
1637
|
+
*/
|
|
1625
1638
|
declare class AxAgent<IN extends AxGenIn, OUT extends AxGenOut = AxGenOut> implements AxAgentic {
|
|
1626
1639
|
private ai?;
|
|
1627
1640
|
private signature;
|
|
@@ -1629,6 +1642,7 @@ declare class AxAgent<IN extends AxGenIn, OUT extends AxGenOut = AxGenOut> imple
|
|
|
1629
1642
|
private functions?;
|
|
1630
1643
|
private agents?;
|
|
1631
1644
|
private disableSmartModelRouting?;
|
|
1645
|
+
private excludeFieldsFromPassthrough;
|
|
1632
1646
|
private name;
|
|
1633
1647
|
private description;
|
|
1634
1648
|
private subAgentList?;
|
|
@@ -1653,9 +1667,20 @@ declare class AxAgent<IN extends AxGenIn, OUT extends AxGenOut = AxGenOut> imple
|
|
|
1653
1667
|
resetUsage(): void;
|
|
1654
1668
|
getFunction(): AxFunction;
|
|
1655
1669
|
getFeatures(): AxAgentFeatures;
|
|
1670
|
+
/**
|
|
1671
|
+
* Initializes the agent's execution context, processing child agents and their functions.
|
|
1672
|
+
*/
|
|
1656
1673
|
private init;
|
|
1657
1674
|
forward(parentAi: Readonly<AxAIService>, values: IN, options?: Readonly<AxProgramForwardOptions>): Promise<OUT>;
|
|
1658
1675
|
streamingForward(parentAi: Readonly<AxAIService>, values: IN, options?: Readonly<AxProgramStreamingForwardOptions>): AxGenStreamingOut<OUT>;
|
|
1676
|
+
/**
|
|
1677
|
+
* Updates the agent's description.
|
|
1678
|
+
* This updates both the stored description and the function's description.
|
|
1679
|
+
*
|
|
1680
|
+
* @param description - New description for the agent (must be at least 20 characters)
|
|
1681
|
+
* @throws Error if description is too short
|
|
1682
|
+
*/
|
|
1683
|
+
setDescription(description: string): void;
|
|
1659
1684
|
}
|
|
1660
1685
|
|
|
1661
1686
|
interface AxApacheTikaArgs {
|
package/index.d.ts
CHANGED
|
@@ -1612,16 +1612,29 @@ declare class AxGen<IN extends AxGenIn = AxGenIn, OUT extends AxGenerateResult<A
|
|
|
1612
1612
|
}, void, unknown>;
|
|
1613
1613
|
}
|
|
1614
1614
|
|
|
1615
|
+
/**
|
|
1616
|
+
* Interface for agents that can be used as child agents.
|
|
1617
|
+
* Provides methods to get the agent's function definition and features.
|
|
1618
|
+
*/
|
|
1615
1619
|
interface AxAgentic extends AxTunable, AxUsable {
|
|
1616
1620
|
getFunction(): AxFunction;
|
|
1617
1621
|
getFeatures(): AxAgentFeatures;
|
|
1618
1622
|
}
|
|
1619
1623
|
type AxAgentOptions = Omit<AxGenOptions, 'functions'> & {
|
|
1620
1624
|
disableSmartModelRouting?: boolean;
|
|
1625
|
+
/** List of field names that should not be automatically passed from parent to child agents */
|
|
1626
|
+
excludeFieldsFromPassthrough?: string[];
|
|
1621
1627
|
};
|
|
1622
1628
|
interface AxAgentFeatures {
|
|
1629
|
+
/** Whether this agent can use smart model routing (requires an AI service) */
|
|
1623
1630
|
canConfigureSmartModelRouting: boolean;
|
|
1631
|
+
/** List of fields that this agent excludes from parent->child value passing */
|
|
1632
|
+
excludeFieldsFromPassthrough: string[];
|
|
1624
1633
|
}
|
|
1634
|
+
/**
|
|
1635
|
+
* An AI agent that can process inputs using an AI service and coordinate with child agents.
|
|
1636
|
+
* Supports features like smart model routing and automatic input field passing to child agents.
|
|
1637
|
+
*/
|
|
1625
1638
|
declare class AxAgent<IN extends AxGenIn, OUT extends AxGenOut = AxGenOut> implements AxAgentic {
|
|
1626
1639
|
private ai?;
|
|
1627
1640
|
private signature;
|
|
@@ -1629,6 +1642,7 @@ declare class AxAgent<IN extends AxGenIn, OUT extends AxGenOut = AxGenOut> imple
|
|
|
1629
1642
|
private functions?;
|
|
1630
1643
|
private agents?;
|
|
1631
1644
|
private disableSmartModelRouting?;
|
|
1645
|
+
private excludeFieldsFromPassthrough;
|
|
1632
1646
|
private name;
|
|
1633
1647
|
private description;
|
|
1634
1648
|
private subAgentList?;
|
|
@@ -1653,9 +1667,20 @@ declare class AxAgent<IN extends AxGenIn, OUT extends AxGenOut = AxGenOut> imple
|
|
|
1653
1667
|
resetUsage(): void;
|
|
1654
1668
|
getFunction(): AxFunction;
|
|
1655
1669
|
getFeatures(): AxAgentFeatures;
|
|
1670
|
+
/**
|
|
1671
|
+
* Initializes the agent's execution context, processing child agents and their functions.
|
|
1672
|
+
*/
|
|
1656
1673
|
private init;
|
|
1657
1674
|
forward(parentAi: Readonly<AxAIService>, values: IN, options?: Readonly<AxProgramForwardOptions>): Promise<OUT>;
|
|
1658
1675
|
streamingForward(parentAi: Readonly<AxAIService>, values: IN, options?: Readonly<AxProgramStreamingForwardOptions>): AxGenStreamingOut<OUT>;
|
|
1676
|
+
/**
|
|
1677
|
+
* Updates the agent's description.
|
|
1678
|
+
* This updates both the stored description and the function's description.
|
|
1679
|
+
*
|
|
1680
|
+
* @param description - New description for the agent (must be at least 20 characters)
|
|
1681
|
+
* @throws Error if description is too short
|
|
1682
|
+
*/
|
|
1683
|
+
setDescription(description: string): void;
|
|
1659
1684
|
}
|
|
1660
1685
|
|
|
1661
1686
|
interface AxApacheTikaArgs {
|
package/index.js
CHANGED
|
@@ -2555,7 +2555,7 @@ var safetySettings = [
|
|
|
2555
2555
|
}
|
|
2556
2556
|
];
|
|
2557
2557
|
var axAIGoogleGeminiDefaultConfig = () => structuredClone({
|
|
2558
|
-
model: "gemini-
|
|
2558
|
+
model: "gemini-2.0-flash" /* Gemini20Flash */,
|
|
2559
2559
|
embedModel: "text-embedding-004" /* TextEmbedding004 */,
|
|
2560
2560
|
safetySettings,
|
|
2561
2561
|
...axBaseAIDefaultConfig()
|
|
@@ -4494,6 +4494,9 @@ var LRUCache = class {
|
|
|
4494
4494
|
};
|
|
4495
4495
|
var globalPrefixCache = new LRUCache(500);
|
|
4496
4496
|
function matchesContent(content, prefix, startIndex = 0, prefixCache = globalPrefixCache) {
|
|
4497
|
+
if (/^\s*$/.test(content)) {
|
|
4498
|
+
return -3;
|
|
4499
|
+
}
|
|
4497
4500
|
const exactMatchIndex = content.indexOf(prefix, startIndex);
|
|
4498
4501
|
if (exactMatchIndex !== -1) {
|
|
4499
4502
|
return exactMatchIndex;
|
|
@@ -5218,6 +5221,9 @@ var streamingExtractValues = (sig, values, xstate, content, streamingValidation
|
|
|
5218
5221
|
// Field is not found, continue to the next field
|
|
5219
5222
|
case -2:
|
|
5220
5223
|
return true;
|
|
5224
|
+
// Partial match at end, skip and gather more content
|
|
5225
|
+
case -3:
|
|
5226
|
+
return true;
|
|
5221
5227
|
}
|
|
5222
5228
|
let prefixLen = prefix.length;
|
|
5223
5229
|
if (xstate.currField) {
|
|
@@ -5987,6 +5993,43 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
5987
5993
|
};
|
|
5988
5994
|
|
|
5989
5995
|
// prompts/agent.ts
|
|
5996
|
+
function processChildAgentFunction(childFunction, parentValues, parentInputKeys, modelList, options) {
|
|
5997
|
+
let processedFunction = { ...childFunction };
|
|
5998
|
+
if (processedFunction.parameters) {
|
|
5999
|
+
const childKeys = processedFunction.parameters.properties ? Object.keys(processedFunction.parameters.properties) : [];
|
|
6000
|
+
const commonKeys = parentInputKeys.filter((key) => childKeys.includes(key)).filter((key) => key !== "model");
|
|
6001
|
+
const injectionKeys = commonKeys.filter(
|
|
6002
|
+
(key) => !options.excludeFieldsFromPassthrough.includes(key)
|
|
6003
|
+
);
|
|
6004
|
+
if (injectionKeys.length > 0) {
|
|
6005
|
+
processedFunction.parameters = removePropertiesFromSchema(
|
|
6006
|
+
processedFunction.parameters,
|
|
6007
|
+
injectionKeys
|
|
6008
|
+
);
|
|
6009
|
+
const originalFunc = processedFunction.func;
|
|
6010
|
+
processedFunction.func = (childArgs, funcOptions) => {
|
|
6011
|
+
const updatedChildArgs = {
|
|
6012
|
+
...childArgs,
|
|
6013
|
+
...pick(parentValues, injectionKeys)
|
|
6014
|
+
};
|
|
6015
|
+
if (options.debug && injectionKeys.length > 0) {
|
|
6016
|
+
process.stdout.write(
|
|
6017
|
+
`Function Params: ${JSON.stringify(updatedChildArgs, null, 2)}`
|
|
6018
|
+
);
|
|
6019
|
+
}
|
|
6020
|
+
return originalFunc(updatedChildArgs, funcOptions);
|
|
6021
|
+
};
|
|
6022
|
+
}
|
|
6023
|
+
return processedFunction;
|
|
6024
|
+
}
|
|
6025
|
+
if (modelList && !options.disableSmartModelRouting && options.canConfigureSmartModelRouting) {
|
|
6026
|
+
processedFunction.parameters = addModelParameter(
|
|
6027
|
+
processedFunction.parameters,
|
|
6028
|
+
modelList
|
|
6029
|
+
);
|
|
6030
|
+
}
|
|
6031
|
+
return processedFunction;
|
|
6032
|
+
}
|
|
5990
6033
|
var AxAgent = class {
|
|
5991
6034
|
ai;
|
|
5992
6035
|
signature;
|
|
@@ -5994,6 +6037,7 @@ var AxAgent = class {
|
|
|
5994
6037
|
functions;
|
|
5995
6038
|
agents;
|
|
5996
6039
|
disableSmartModelRouting;
|
|
6040
|
+
excludeFieldsFromPassthrough;
|
|
5997
6041
|
name;
|
|
5998
6042
|
description;
|
|
5999
6043
|
subAgentList;
|
|
@@ -6010,6 +6054,7 @@ var AxAgent = class {
|
|
|
6010
6054
|
this.agents = agents;
|
|
6011
6055
|
this.functions = functions;
|
|
6012
6056
|
this.disableSmartModelRouting = options?.disableSmartModelRouting;
|
|
6057
|
+
this.excludeFieldsFromPassthrough = options?.excludeFieldsFromPassthrough ?? [];
|
|
6013
6058
|
this.signature = new AxSignature(signature);
|
|
6014
6059
|
this.signature.setDescription(description);
|
|
6015
6060
|
if (!name || name.length < 5) {
|
|
@@ -6078,15 +6123,34 @@ var AxAgent = class {
|
|
|
6078
6123
|
}
|
|
6079
6124
|
getFeatures() {
|
|
6080
6125
|
return {
|
|
6081
|
-
canConfigureSmartModelRouting: this.ai
|
|
6126
|
+
canConfigureSmartModelRouting: this.ai === void 0,
|
|
6127
|
+
excludeFieldsFromPassthrough: this.excludeFieldsFromPassthrough
|
|
6082
6128
|
};
|
|
6083
6129
|
}
|
|
6084
|
-
|
|
6130
|
+
/**
|
|
6131
|
+
* Initializes the agent's execution context, processing child agents and their functions.
|
|
6132
|
+
*/
|
|
6133
|
+
init(parentAi, values, options) {
|
|
6085
6134
|
const ai = this.ai ?? parentAi;
|
|
6086
6135
|
const mm = ai?.getModelList();
|
|
6087
|
-
const
|
|
6088
|
-
|
|
6089
|
-
)
|
|
6136
|
+
const parentSchema = this.signature.getInputFields();
|
|
6137
|
+
const parentKeys = parentSchema.map((p) => p.name);
|
|
6138
|
+
const agentFuncs = this.agents?.map((agent) => {
|
|
6139
|
+
const f = agent.getFeatures();
|
|
6140
|
+
const processOptions = {
|
|
6141
|
+
debug: ai?.getOptions()?.debug ?? false,
|
|
6142
|
+
disableSmartModelRouting: !!this.disableSmartModelRouting,
|
|
6143
|
+
excludeFieldsFromPassthrough: f.excludeFieldsFromPassthrough,
|
|
6144
|
+
canConfigureSmartModelRouting: f.canConfigureSmartModelRouting
|
|
6145
|
+
};
|
|
6146
|
+
return processChildAgentFunction(
|
|
6147
|
+
agent.getFunction(),
|
|
6148
|
+
values,
|
|
6149
|
+
parentKeys,
|
|
6150
|
+
mm,
|
|
6151
|
+
processOptions
|
|
6152
|
+
);
|
|
6153
|
+
});
|
|
6090
6154
|
const functions = [
|
|
6091
6155
|
...options?.functions ?? this.functions ?? [],
|
|
6092
6156
|
...agentFuncs ?? []
|
|
@@ -6094,16 +6158,33 @@ var AxAgent = class {
|
|
|
6094
6158
|
return { ai, functions };
|
|
6095
6159
|
}
|
|
6096
6160
|
async forward(parentAi, values, options) {
|
|
6097
|
-
const { ai, functions } = this.init(parentAi, options);
|
|
6161
|
+
const { ai, functions } = this.init(parentAi, values, options);
|
|
6098
6162
|
return await this.program.forward(ai, values, { ...options, functions });
|
|
6099
6163
|
}
|
|
6100
6164
|
async *streamingForward(parentAi, values, options) {
|
|
6101
|
-
const { ai, functions } = this.init(parentAi, options);
|
|
6165
|
+
const { ai, functions } = this.init(parentAi, values, options);
|
|
6102
6166
|
return yield* this.program.streamingForward(ai, values, {
|
|
6103
6167
|
...options,
|
|
6104
6168
|
functions
|
|
6105
6169
|
});
|
|
6106
6170
|
}
|
|
6171
|
+
/**
|
|
6172
|
+
* Updates the agent's description.
|
|
6173
|
+
* This updates both the stored description and the function's description.
|
|
6174
|
+
*
|
|
6175
|
+
* @param description - New description for the agent (must be at least 20 characters)
|
|
6176
|
+
* @throws Error if description is too short
|
|
6177
|
+
*/
|
|
6178
|
+
setDescription(description) {
|
|
6179
|
+
if (!description || description.length < 20) {
|
|
6180
|
+
throw new Error(
|
|
6181
|
+
"Agent description must be at least 20 characters (explain in detail what the agent does)"
|
|
6182
|
+
);
|
|
6183
|
+
}
|
|
6184
|
+
this.description = description;
|
|
6185
|
+
this.signature.setDescription(description);
|
|
6186
|
+
this.func.description = description;
|
|
6187
|
+
}
|
|
6107
6188
|
};
|
|
6108
6189
|
function toCamelCase(inputString) {
|
|
6109
6190
|
const words = inputString.split(/[^a-zA-Z0-9]/);
|
|
@@ -6128,7 +6209,7 @@ function addModelParameter(parameters, models) {
|
|
|
6128
6209
|
const modelProperty = {
|
|
6129
6210
|
type: "string",
|
|
6130
6211
|
enum: models.map((m) => m.key),
|
|
6131
|
-
description: `The AI model to use for this function call. Available options: ${models.map((m) =>
|
|
6212
|
+
description: `The AI model to use for this function call. Available options: ${models.map((m) => `\`${m.key}\` ${m.description}`).join(", ")}`
|
|
6132
6213
|
};
|
|
6133
6214
|
const newProperties = {
|
|
6134
6215
|
...baseSchema.properties ?? {},
|
|
@@ -6141,6 +6222,34 @@ function addModelParameter(parameters, models) {
|
|
|
6141
6222
|
required: newRequired
|
|
6142
6223
|
};
|
|
6143
6224
|
}
|
|
6225
|
+
function removePropertiesFromSchema(schema, keys) {
|
|
6226
|
+
const newSchema = structuredClone(schema);
|
|
6227
|
+
if (newSchema.properties) {
|
|
6228
|
+
for (const key of keys) {
|
|
6229
|
+
delete newSchema.properties[key];
|
|
6230
|
+
}
|
|
6231
|
+
}
|
|
6232
|
+
if (Array.isArray(newSchema.required)) {
|
|
6233
|
+
const filteredRequired = newSchema.required.filter(
|
|
6234
|
+
(r) => !keys.includes(r)
|
|
6235
|
+
);
|
|
6236
|
+
Object.defineProperty(newSchema, "required", {
|
|
6237
|
+
value: filteredRequired,
|
|
6238
|
+
writable: true,
|
|
6239
|
+
configurable: true
|
|
6240
|
+
});
|
|
6241
|
+
}
|
|
6242
|
+
return newSchema;
|
|
6243
|
+
}
|
|
6244
|
+
function pick(obj, keys) {
|
|
6245
|
+
const result = {};
|
|
6246
|
+
for (const key of keys) {
|
|
6247
|
+
if (key in obj) {
|
|
6248
|
+
result[key] = obj[key];
|
|
6249
|
+
}
|
|
6250
|
+
}
|
|
6251
|
+
return result;
|
|
6252
|
+
}
|
|
6144
6253
|
|
|
6145
6254
|
// docs/tika.ts
|
|
6146
6255
|
import { createReadStream } from "node:fs";
|