AxilJS AI Agents with Tool Calling
Build AI agents in TypeScript with AxilJS using tool calling, custom tools, multi-step execution, and streaming.
AI Agents with Tool Calling
AxilJS provides an AI agent API for building TypeScript and Node.js AI applications with tool calling, multi-step execution, custom tools, and streaming.
An Agent can receive a user request, decide which tools to use, execute those tools, and return the final response. This makes it suitable for applications that need AI models to interact with external functions or services.
Setup
Create an agent with an AI provider and one or more tools.
The tools option defines the functions available to the agent. maxIterations controls the maximum number of agent execution steps.
Run an AI Agent
Use agent.run() to execute a request and receive the result.
The returned result provides the agent's final response along with its execution steps.
This execution model is useful when an AI agent needs to perform one or more tool calls before producing its final answer.
Create Custom AI Tools
You can define application-specific tools with createTool().
For example, a weather tool can expose a function that an agent can call when it needs weather information.
A custom tool defines:
name— the identifier used by the agent.description— explains what the tool does.parameters— describes the tool input.handler— contains the function executed when the tool is called.
This allows you to connect AxilJS agents to application logic, APIs, databases, services, and other external capabilities.
Stream Agent Execution
For applications that need incremental agent execution, use runStream().
The stream exposes individual execution steps as they become available. Each step can include the agent's thought, toolCalls, and finalAnswer.
Streaming is useful for interactive AI applications where you want to observe or process agent execution progressively instead of waiting for the complete result.
Agent Workflow
A typical AxilJS agent workflow consists of:
- Create an
Agentwith an AI provider. - Register built-in or custom tools.
- Send a request with
agent.run(). - Allow the agent to execute the required tools.
- Read the final response and execution steps.
- Use
runStream()when incremental execution is required.
When to Use AxilJS Agents
AxilJS agents are useful when an AI application needs to go beyond generating text and interact with executable tools.
Common use cases include:
- AI assistants with external tools
- Calculator and utility agents
- Weather and API integrations
- Database-aware AI applications
- Automated workflows
- Multi-step AI operations
- Interactive streaming agents