Airtrain is a lightweight agent and LLM framework for building, testing, and monitoring AI systems. This is the official Node.js implementation of Airtrain.
- 🔄 Cross-platform: JavaScript/TypeScript implementation of Airtrain, compatible with the Python version
- 🧩 Modular: Build AI agents from composable skills with a simple, consistent API
- 💾 Secure credentials: Robust credential management for API keys and secrets
- 📊 Telemetry: Built-in telemetry for monitoring and improving your AI systems
- 🚀 Model Integrations: Support for multiple model providers including Fireworks AI
- 🛠 Type-Safe: Fully typed with TypeScript for better developer experience
npm install airtrain
import { Skill, telemetry } from 'airtrain';
import { FireworksClient } from 'airtrain/integrations/fireworks';
// Initialize with your API key (or use environment variables)
const client = new FireworksClient({
apiKey: process.env.FIREWORKS_API_KEY
});
// Create a skill
const answerQuestion = new Skill({
name: "answerQuestion",
description: "Answers general knowledge questions",
execute: async ({ input }) => {
const response = await client.createChatCompletion([
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: input }
]);
return response.choices[0]?.message?.content || "No response from model";
}
});
// Use the skill
async function main() {
const result = await answerQuestion.process("What is the capital of France?");
console.log(result);
}
main().catch(console.error);
The library uses Zod for validation:
import { BaseSchema } from 'airtrain';
import { z } from 'zod';
// Define a schema for your skill's input
const MyInputSchema = BaseSchema.extend({
question: z.string().nonempty(),
context: z.string().optional()
});
// Type inference works automatically
type MyInput = z.infer<typeof MyInputSchema>;
Securely manage API keys and other sensitive information:
import { Credentials } from 'airtrain';
// Create credentials manager
const credentials = new Credentials({
configPath: './config',
encryptionKey: process.env.ENCRYPTION_KEY
});
// Save an API key
await credentials.set('fireworks', { apiKey: 'your-api-key' });
// Use the credentials
const apiKey = (await credentials.get('fireworks')).apiKey;
Build modular, reusable components:
import { Skill } from 'airtrain';
import { z } from 'zod';
const translator = new Skill({
name: "translator",
description: "Translates text to another language",
input_schema: z.object({
text: z.string(),
target_language: z.string()
}),
execute: async ({ input }) => {
// Implementation using your preferred LLM
return translatedText;
}
});
The library includes integrations with popular LLM providers:
-
Fireworks AI: High-performance, cost-effective LLMs
import { FireworksClient } from 'airtrain/integrations/fireworks'; const client = new FireworksClient({ apiKey: process.env.FIREWORKS_API_KEY, defaultModel: "accounts/fireworks/models/llama-v3-70b-instruct" }); const response = await client.createChatCompletion([ { role: "user", content: "Hello!" } ]);
Explore the examples directory for detailed usage examples:
- Basic skills: How to create and use skills
- Fireworks integration: Chat, streaming, function calling examples
- Credential management: Secure storage and retrieval of credentials
# Clone the repository
git clone <repository-url>
cd airtrain-node
# Install dependencies
npm install
# Build the project
npm run build
# Run tests
npm test
# Run with coverage
npm run test:coverage
The library includes a dedicated script for publishing to NPM:
# Create a .env file with your NPM token
cp .env.example .env
# Edit the .env file to add your NPM_TOKEN
# Run the publishing script
npm run publish-npm
The script will:
- Validate your package.json
- Check git status and branch
- Let you choose a version bump (patch, minor, major)
- Build and test the package
- Publish to NPM with your token
For a dry run (without actually publishing):
npm run publish-npm -- --dry-run
MIT
Contributions are welcome! Please see CONTRIBUTING.md for details.