agent
Call Signature
function agent<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/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/prompts/agent.ts#L682
Creates a strongly-typed AI agent from a signature. This is the recommended way to create agents, providing better type inference and cleaner syntax. Supports both string signatures and AxSignature objects.
Example
// Using string signature
const myAgent = agent('userInput:string -> responseText:string', {
name: 'myAgent',
description: 'An agent that processes user input and returns a response',
definition: 'You are a helpful assistant that responds to user queries...'
});
// Using AxSignature object
const sig = s('userInput:string -> responseText:string');
const myAgent2 = agent(sig, {
name: 'myAgent2',
description: 'Same agent but using AxSignature object'
});
// With child agents
const parentAgent = agent('taskDescription:string -> completedTask:string', {
name: 'parentAgent',
description: 'Coordinates child agents to complete tasks',
agents: [childAgent1, childAgent2]
});
// Type-safe usage
const result = await myAgent.forward(ai, { userInput: 'Hello!' });
console.log(result.responseText); // TypeScript knows this exists
Type Parameters
| Type Parameter |
|---|
T extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
signature | T | The input/output signature as a string or AxSignature object |
config | AxAgentConfig<ParseSignature<T>["inputs"], ParseSignature<T>["outputs"]> | Configuration options for the agent |
Returns
AxAgent<ParseSignature<T>["inputs"], ParseSignature<T>["outputs"]>
A typed agent instance
Call Signature
function agent<TInput, TOutput>(signature: AxSignature<TInput, TOutput>, config: AxAgentConfig<TInput, TOutput>): AxAgent<TInput, TOutput>;
Defined in: https://github.com/ax-llm/ax/blob/d2df625e2c2fd70a090d6321c042579c2819f0d1/src/ax/prompts/agent.ts#L689
Creates a strongly-typed AI agent from a signature. This is the recommended way to create agents, providing better type inference and cleaner syntax. Supports both string signatures and AxSignature objects.
Example
// Using string signature
const myAgent = agent('userInput:string -> responseText:string', {
name: 'myAgent',
description: 'An agent that processes user input and returns a response',
definition: 'You are a helpful assistant that responds to user queries...'
});
// Using AxSignature object
const sig = s('userInput:string -> responseText:string');
const myAgent2 = agent(sig, {
name: 'myAgent2',
description: 'Same agent but using AxSignature object'
});
// With child agents
const parentAgent = agent('taskDescription:string -> completedTask:string', {
name: 'parentAgent',
description: 'Coordinates child agents to complete tasks',
agents: [childAgent1, childAgent2]
});
// Type-safe usage
const result = await myAgent.forward(ai, { userInput: 'Hello!' });
console.log(result.responseText); // TypeScript knows this exists
Type Parameters
| Type Parameter |
|---|
TInput extends Record<string, any> |
TOutput extends Record<string, any> |
Parameters
| Parameter | Type | Description |
|---|---|---|
signature | AxSignature<TInput, TOutput> | The input/output signature as a string or AxSignature object |
config | AxAgentConfig<TInput, TOutput> | Configuration options for the agent |
Returns
AxAgent<TInput, TOutput>
A typed agent instance