AxAgent
Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/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/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L194
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
applyOptimization()
applyOptimization(optimizedProgram: any): void;
Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L503
Parameters
Parameter | Type |
---|---|
optimizedProgram | any |
Returns
void
Implementation of
forward()
forward<T>(
parentAi: T,
values: IN | AxMessage<IN>[],
options?: Readonly<AxProgramForwardOptionsWithModels<T>>): Promise<OUT>;
Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L436
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/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L384
Returns
Implementation of
getFunction()
getFunction(): AxFunction;
Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L344
Returns
Implementation of
getSignature()
getSignature(): AxSignature;
Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L493
Returns
Implementation of
getTraces()
getTraces(): AxProgramTrace<IN, OUT>[];
Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L328
Returns
AxProgramTrace
<IN
, OUT
>[]
Implementation of
getUsage()
getUsage(): AxModelUsage & object[];
Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L336
Returns
AxModelUsage
& object
[]
Implementation of
resetUsage()
resetUsage(): void;
Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L340
Returns
void
Implementation of
setDefinition()
setDefinition(definition: string): void;
Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L484
Parameters
Parameter | Type |
---|---|
definition | string |
Returns
void
setDemos()
setDemos(demos: readonly AxProgramDemos<IN, OUT>[]): void;
Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L332
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/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L475
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/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L313
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/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L320
Parameters
Parameter | Type |
---|---|
id | string |
Returns
void
Implementation of
setParentId()
setParentId(parentId: string): void;
Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L324
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/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L497
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/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L452
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/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/prompts/agent.ts#L288
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