How AXAR agents work: Tools, Schemas, and Dynamic Prompts
mainAXAR agents can be extended with advanced features to create robust applications:
- Structured Data (
@schema,@output): Use the@schema()decorator to define classes for structured inputs or outputs. Use@property()to describe fields. The@output(SchemaClass)decorator on an agent ensures the LLM returns data matching that schema. - Tools (
@tool): Define methods within your agent class and decorate them with@tool("description"). These methods become functions the agent can call to interact with external systems. - Dynamic Prompts (
@systemPrompt): You can define methods decorated with@systemPrompt()that return aPromise<string>. AXAR will call these methods to inject dynamic context into the system prompt at runtime. - Dependency Injection: Since agents are standard TypeScript classes, you can use constructor injection to pass database connections, API clients, or other services into your agent.
@schema()
export class SupportResponse {
@property('Human-readable advice to give to the customer.')
support_advice!: string;
@property("Whether to block customer's card.")
block_card!: boolean;
}
@model('openai:gpt-4o-mini')
@output(SupportResponse)
export class SupportAgent extends Agent<string, SupportResponse> {
constructor(private db: DatabaseConn) { super(); }
@systemPrompt()
async getCustomerContext(): Promise<string> {
return `Context from DB`;
}
@tool("Get balance")
async customerBalance(params: any): Promise<number> {
return 123.45;
}
}