AxAgent
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L178
An AI agent that can process inputs using an AI service and coordinate with child agents. Supports features like smart model routing and automatic input field passing to child agents.
Deprecated
Use the agent()
factory function instead of instantiating this class directly.
The factory function provides better type inference and cleaner syntax.
This class will be removed in v15.0.0.
Migration timeline:
- v13.0.24+: Deprecation warnings (current)
- v14.0.0: Runtime console warnings
- v15.0.0: Complete removal
Example
// Old (deprecated):
const myAgent = new AxAgent({
name: 'myAgent',
description: 'An agent that does something',
signature: 'userInput:string -> responseText:string'
});
// New (recommended):
const myAgent = agent('userInput:string -> responseText:string', {
name: 'myAgent',
description: 'An agent that does something'
});
Type Parameters
Type Parameter |
---|
IN extends AxGenIn |
OUT extends AxGenOut |
Implements
AxAgentic
<IN
,OUT
>
Constructors
Constructor
new AxAgent<IN, OUT>(__namedParameters: Readonly<{
agents?: AxAgentic<IN, OUT>[];
ai?: Readonly<AxAIService>;
definition?: string;
description: string;
functions?: AxInputFunctionType;
name: string;
signature: NonNullable<ConstructorParameters<typeof AxSignature>[0]>;
}>, options?: Readonly<AxAgentOptions>): AxAgent<IN, OUT>;
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L193
Parameters
Parameter | Type |
---|---|
__namedParameters | Readonly <{ agents? : AxAgentic <IN , OUT >[]; ai? : Readonly <AxAIService >; definition? : string ; description : string ; functions? : AxInputFunctionType ; name : string ; signature : NonNullable <ConstructorParameters <typeof AxSignature >[0 ]>; }> |
options? | Readonly <AxAgentOptions > |
Returns
AxAgent
<IN
, OUT
>
Methods
forward()
forward<T>(
parentAi: T,
values: IN | AxMessage<IN>[],
options?: Readonly<AxProgramForwardOptionsWithModels<T>>): Promise<OUT>;
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L434
Type Parameters
Type Parameter |
---|
T extends Readonly <AxAIService <unknown , unknown , string >> |
Parameters
Parameter | Type |
---|---|
parentAi | T |
values | IN | AxMessage <IN >[] |
options? | Readonly <AxProgramForwardOptionsWithModels <T >> |
Returns
Promise
<OUT
>
Implementation of
getFeatures()
getFeatures(): AxAgentFeatures;
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L382
Returns
Implementation of
getFunction()
getFunction(): AxFunction;
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L342
Returns
Implementation of
getSignature()
getSignature(): AxSignature;
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L485
Returns
Implementation of
getTraces()
getTraces(): AxProgramTrace<IN, OUT>[];
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L326
Returns
AxProgramTrace
<IN
, OUT
>[]
Implementation of
getUsage()
getUsage(): AxModelUsage & object[];
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L334
Returns
AxModelUsage
& object
[]
Implementation of
resetUsage()
resetUsage(): void;
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L338
Returns
void
Implementation of
setDefinition()
setDefinition(definition: string): void;
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L476
Parameters
Parameter | Type |
---|---|
definition | string |
Returns
void
setDemos()
setDemos(demos: readonly AxProgramDemos<IN, OUT>[]): void;
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L330
Parameters
Parameter | Type |
---|---|
demos | readonly AxProgramDemos <IN , OUT >[] |
Returns
void
Implementation of
setDescription()
setDescription(description: string): void;
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L467
Updates the agent’s description. This updates both the stored description and the function’s description.
Parameters
Parameter | Type | Description |
---|---|---|
description | string | New description for the agent (must be at least 20 characters) |
Returns
void
Throws
Error if description is too short
setExamples()
setExamples(examples: Readonly<AxProgramExamples<IN, OUT>>, options?: Readonly<AxSetExamplesOptions>): void;
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L311
Parameters
Parameter | Type |
---|---|
examples | Readonly <AxProgramExamples <IN , OUT >> |
options? | Readonly <AxSetExamplesOptions > |
Returns
void
Implementation of
setId()
setId(id: string): void;
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L318
Parameters
Parameter | Type |
---|---|
id | string |
Returns
void
Implementation of
setParentId()
setParentId(parentId: string): void;
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L322
Parameters
Parameter | Type |
---|---|
parentId | string |
Returns
void
Implementation of
setSignature()
setSignature(signature: NonNullable<
| undefined
| Readonly<
| string
| AxSignature<Record<string, any>, Record<string, any>>
| AxSignatureConfig>>): void;
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L489
Parameters
Parameter | Type |
---|---|
signature | NonNullable < | undefined | Readonly < | string | AxSignature <Record <string , any >, Record <string , any >> | AxSignatureConfig >> |
Returns
void
streamingForward()
streamingForward<T>(
parentAi: T,
values: IN | AxMessage<IN>[],
options?: Readonly<AxProgramStreamingForwardOptionsWithModels<T>>): AxGenStreamingOut<OUT>;
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L447
Type Parameters
Type Parameter |
---|
T extends Readonly <AxAIService <unknown , unknown , string >> |
Parameters
Parameter | Type |
---|---|
parentAi | T |
values | IN | AxMessage <IN >[] |
options? | Readonly <AxProgramStreamingForwardOptionsWithModels <T >> |
Returns
AxGenStreamingOut
<OUT
>
Implementation of
create()
static create<T>(signature: T, config: AxAgentConfig<ParseSignature<T>["inputs"], ParseSignature<T>["outputs"]>): AxAgent<ParseSignature<T>["inputs"], ParseSignature<T>["outputs"]>;
Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L286
Creates a new AxAgent instance with type-safe signature parsing. This is the recommended way to create agents with string-based signatures.
Example
const agent = AxAgent.create(
'userInput:string "User question" -> responseText:string "Agent response"',
{
name: 'helpfulAgent',
description: 'An agent that provides helpful responses to user questions',
definition: 'You are a helpful assistant that provides clear, accurate responses to user questions.',
ai: llm
}
);
Type Parameters
Type Parameter |
---|
T extends string |
Parameters
Parameter | Type | Description |
---|---|---|
signature | T | The signature string defining input/output fields |
config | AxAgentConfig <ParseSignature <T >["inputs" ], ParseSignature <T >["outputs" ]> | Agent configuration including name, description, etc. |
Returns
AxAgent
<ParseSignature
<T
>["inputs"
], ParseSignature
<T
>["outputs"
]>
A new AxAgent instance with inferred types