amiai
v0.1.4
Published
AMIAI SDK - Build AI agents with local tool execution
Readme
amiai
Build AI agents with local tool execution.
Installation
npm install amiaiQuick Start
1. Create a tool
// search.tool.ts
import { tool } from 'amiai';
export const search = tool({
name: 'web_search',
description: 'Search the web',
input: {
query: { type: 'string', description: 'Search query' }
},
execute: async (input) => {
const res = await fetch(`https://api.example.com/search?q=${input.query}`);
return res.json();
}
});2. Run
AMIAI_API_KEY=xxx npx amiai devAPI
tool(config)
import { tool } from 'amiai';
const myTool = tool({
name: 'my_tool',
description: 'What it does',
input: {
param: { type: 'string', description: 'Description' }
},
execute: async (input) => {
return { result: 'data' };
}
});Harness
import { Harness } from 'amiai';
const harness = new Harness({
apiKey: process.env.AMIAI_API_KEY!,
tools: [myTool],
});
await harness.start();Examples
Calculator
import { tool } from 'amiai';
export const calculator = tool({
name: 'calculator',
description: 'Evaluate math expressions',
input: {
expression: { type: 'string', description: 'e.g., 2 + 2' }
},
execute: async (input) => {
const result = new Function(`return (${input.expression})`)();
return { result };
}
});File Reader
import { tool } from 'amiai';
import { readFile } from 'fs/promises';
export const fileReader = tool({
name: 'read_file',
description: 'Read a file',
input: {
path: { type: 'string', description: 'File path' }
},
execute: async (input) => {
const content = await readFile(input.path, 'utf-8');
return { content };
}
});License
MIT
