@ax-llm/ax 11.0.6 → 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 +103 -7
- package/index.cjs.map +1 -1
- package/index.d.cts +25 -0
- package/index.d.ts +25 -0
- package/index.js +103 -7
- 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
|
@@ -5987,6 +5987,37 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
5987
5987
|
};
|
|
5988
5988
|
|
|
5989
5989
|
// prompts/agent.ts
|
|
5990
|
+
function processChildAgentFunction(childFunction, parentValues, parentInputKeys, modelList, options) {
|
|
5991
|
+
let processedFunction = { ...childFunction };
|
|
5992
|
+
if (processedFunction.parameters) {
|
|
5993
|
+
const childKeys = processedFunction.parameters.properties ? Object.keys(processedFunction.parameters.properties) : [];
|
|
5994
|
+
const commonKeys = parentInputKeys.filter((key) => childKeys.includes(key)).filter((key) => key !== "model");
|
|
5995
|
+
const injectionKeys = commonKeys.filter(
|
|
5996
|
+
(key) => !options.excludeFieldsFromPassthrough.includes(key)
|
|
5997
|
+
);
|
|
5998
|
+
if (injectionKeys.length > 0) {
|
|
5999
|
+
processedFunction.parameters = removePropertiesFromSchema(
|
|
6000
|
+
processedFunction.parameters,
|
|
6001
|
+
injectionKeys
|
|
6002
|
+
);
|
|
6003
|
+
const originalFunc = processedFunction.func;
|
|
6004
|
+
processedFunction.func = (childArgs, funcOptions) => originalFunc(
|
|
6005
|
+
{
|
|
6006
|
+
...childArgs,
|
|
6007
|
+
...pick(parentValues, injectionKeys)
|
|
6008
|
+
},
|
|
6009
|
+
funcOptions
|
|
6010
|
+
);
|
|
6011
|
+
}
|
|
6012
|
+
}
|
|
6013
|
+
if (modelList && !options.disableSmartModelRouting && options.canConfigureSmartModelRouting) {
|
|
6014
|
+
processedFunction.parameters = addModelParameter(
|
|
6015
|
+
processedFunction.parameters,
|
|
6016
|
+
modelList
|
|
6017
|
+
);
|
|
6018
|
+
}
|
|
6019
|
+
return processedFunction;
|
|
6020
|
+
}
|
|
5990
6021
|
var AxAgent = class {
|
|
5991
6022
|
ai;
|
|
5992
6023
|
signature;
|
|
@@ -5994,6 +6025,7 @@ var AxAgent = class {
|
|
|
5994
6025
|
functions;
|
|
5995
6026
|
agents;
|
|
5996
6027
|
disableSmartModelRouting;
|
|
6028
|
+
excludeFieldsFromPassthrough;
|
|
5997
6029
|
name;
|
|
5998
6030
|
description;
|
|
5999
6031
|
subAgentList;
|
|
@@ -6010,6 +6042,7 @@ var AxAgent = class {
|
|
|
6010
6042
|
this.agents = agents;
|
|
6011
6043
|
this.functions = functions;
|
|
6012
6044
|
this.disableSmartModelRouting = options?.disableSmartModelRouting;
|
|
6045
|
+
this.excludeFieldsFromPassthrough = options?.excludeFieldsFromPassthrough ?? [];
|
|
6013
6046
|
this.signature = new AxSignature(signature);
|
|
6014
6047
|
this.signature.setDescription(description);
|
|
6015
6048
|
if (!name || name.length < 5) {
|
|
@@ -6078,15 +6111,33 @@ var AxAgent = class {
|
|
|
6078
6111
|
}
|
|
6079
6112
|
getFeatures() {
|
|
6080
6113
|
return {
|
|
6081
|
-
canConfigureSmartModelRouting: this.ai
|
|
6114
|
+
canConfigureSmartModelRouting: this.ai === void 0,
|
|
6115
|
+
excludeFieldsFromPassthrough: this.excludeFieldsFromPassthrough
|
|
6082
6116
|
};
|
|
6083
6117
|
}
|
|
6084
|
-
|
|
6118
|
+
/**
|
|
6119
|
+
* Initializes the agent's execution context, processing child agents and their functions.
|
|
6120
|
+
*/
|
|
6121
|
+
init(parentAi, values, options) {
|
|
6085
6122
|
const ai = this.ai ?? parentAi;
|
|
6086
6123
|
const mm = ai?.getModelList();
|
|
6087
|
-
const
|
|
6088
|
-
|
|
6089
|
-
)
|
|
6124
|
+
const parentSchema = this.signature.toJSONSchema();
|
|
6125
|
+
const parentKeys = parentSchema.properties ? Object.keys(parentSchema.properties) : [];
|
|
6126
|
+
const agentFuncs = this.agents?.map((agent) => {
|
|
6127
|
+
const f = agent.getFeatures();
|
|
6128
|
+
const processOptions = {
|
|
6129
|
+
disableSmartModelRouting: !!this.disableSmartModelRouting,
|
|
6130
|
+
excludeFieldsFromPassthrough: f.excludeFieldsFromPassthrough,
|
|
6131
|
+
canConfigureSmartModelRouting: f.canConfigureSmartModelRouting
|
|
6132
|
+
};
|
|
6133
|
+
return processChildAgentFunction(
|
|
6134
|
+
agent.getFunction(),
|
|
6135
|
+
values,
|
|
6136
|
+
parentKeys,
|
|
6137
|
+
mm,
|
|
6138
|
+
processOptions
|
|
6139
|
+
);
|
|
6140
|
+
});
|
|
6090
6141
|
const functions = [
|
|
6091
6142
|
...options?.functions ?? this.functions ?? [],
|
|
6092
6143
|
...agentFuncs ?? []
|
|
@@ -6094,16 +6145,33 @@ var AxAgent = class {
|
|
|
6094
6145
|
return { ai, functions };
|
|
6095
6146
|
}
|
|
6096
6147
|
async forward(parentAi, values, options) {
|
|
6097
|
-
const { ai, functions } = this.init(parentAi, options);
|
|
6148
|
+
const { ai, functions } = this.init(parentAi, values, options);
|
|
6098
6149
|
return await this.program.forward(ai, values, { ...options, functions });
|
|
6099
6150
|
}
|
|
6100
6151
|
async *streamingForward(parentAi, values, options) {
|
|
6101
|
-
const { ai, functions } = this.init(parentAi, options);
|
|
6152
|
+
const { ai, functions } = this.init(parentAi, values, options);
|
|
6102
6153
|
return yield* this.program.streamingForward(ai, values, {
|
|
6103
6154
|
...options,
|
|
6104
6155
|
functions
|
|
6105
6156
|
});
|
|
6106
6157
|
}
|
|
6158
|
+
/**
|
|
6159
|
+
* Updates the agent's description.
|
|
6160
|
+
* This updates both the stored description and the function's description.
|
|
6161
|
+
*
|
|
6162
|
+
* @param description - New description for the agent (must be at least 20 characters)
|
|
6163
|
+
* @throws Error if description is too short
|
|
6164
|
+
*/
|
|
6165
|
+
setDescription(description) {
|
|
6166
|
+
if (!description || description.length < 20) {
|
|
6167
|
+
throw new Error(
|
|
6168
|
+
"Agent description must be at least 20 characters (explain in detail what the agent does)"
|
|
6169
|
+
);
|
|
6170
|
+
}
|
|
6171
|
+
this.description = description;
|
|
6172
|
+
this.signature.setDescription(description);
|
|
6173
|
+
this.func.description = description;
|
|
6174
|
+
}
|
|
6107
6175
|
};
|
|
6108
6176
|
function toCamelCase(inputString) {
|
|
6109
6177
|
const words = inputString.split(/[^a-zA-Z0-9]/);
|
|
@@ -6141,6 +6209,34 @@ function addModelParameter(parameters, models) {
|
|
|
6141
6209
|
required: newRequired
|
|
6142
6210
|
};
|
|
6143
6211
|
}
|
|
6212
|
+
function removePropertiesFromSchema(schema, keys) {
|
|
6213
|
+
const newSchema = structuredClone(schema);
|
|
6214
|
+
if (newSchema.properties) {
|
|
6215
|
+
for (const key of keys) {
|
|
6216
|
+
delete newSchema.properties[key];
|
|
6217
|
+
}
|
|
6218
|
+
}
|
|
6219
|
+
if (Array.isArray(newSchema.required)) {
|
|
6220
|
+
const filteredRequired = newSchema.required.filter(
|
|
6221
|
+
(r) => !keys.includes(r)
|
|
6222
|
+
);
|
|
6223
|
+
Object.defineProperty(newSchema, "required", {
|
|
6224
|
+
value: filteredRequired,
|
|
6225
|
+
writable: true,
|
|
6226
|
+
configurable: true
|
|
6227
|
+
});
|
|
6228
|
+
}
|
|
6229
|
+
return newSchema;
|
|
6230
|
+
}
|
|
6231
|
+
function pick(obj, keys) {
|
|
6232
|
+
const result = {};
|
|
6233
|
+
for (const key of keys) {
|
|
6234
|
+
if (key in obj) {
|
|
6235
|
+
result[key] = obj[key];
|
|
6236
|
+
}
|
|
6237
|
+
}
|
|
6238
|
+
return result;
|
|
6239
|
+
}
|
|
6144
6240
|
|
|
6145
6241
|
// docs/tika.ts
|
|
6146
6242
|
import { createReadStream } from "node:fs";
|