agent
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/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L661
Creates a strongly-typed AI agent from a string signature. This is the recommended way to create agents, providing better type inference and cleaner syntax.
Example
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...'
});
// 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 (e.g., “userInput:string -> responseText:string”) |
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