@astrive-ai/sdk
v1.0.53
Published
AstriveAI - Universal AI Agent Framework
Maintainers
Readme
@astrive-ai/sdk
Astrive AI is a powerful, universal, and highly adaptable Agentic AI SDK designed for developers. Build autonomous AI agents that can seamlessly integrate into your CLI, Web Server (Express/Next.js), or messaging platforms (Telegram, WhatsApp, Discord).
With built-in native capabilities like dynamic code execution (RuntimeEvalTool) and media delivery (SendMediaTool), Astrive AI breaks the boundaries of traditional chatbots, allowing the AI to interact directly with your host application to perform tasks automatically.
🚀 Installation
npm install @astrive-ai/sdk🌟 Key Features
- Autonomous Tooling System: Includes pre-built tools (Web Search, Filesystem, Terminal, Media Downloader, Vision, and more).
- Universal Event Emitter: Agent can emit events (e.g.
media:send) to communicate media intent directly to your app. - Runtime Execution (The Bridge): Expose your platform's API (e.g., Express
res, Telegrambot) to the agent so it can dynamically write and execute code inside your Node.js runtime! - Memory & Planner: Built-in context memory and multi-step execution planning.
- Provider Agnostic: Easily plug in your own models (Gemini, OpenAI, Anthropic, etc.).
🛠️ Quick Start (Basic Agent)
import { createAgent } from '@astrive-ai/sdk';
const agent = createAgent({
providers: { /* Your Provider Setup */ }
});
async function run() {
await agent.init();
const response = await agent.chat({ message: "Hello! Tell me a joke." });
console.log(response.content);
}
run();🤯 The Magic: RuntimeEvalTool (Universal Bridge)
The RuntimeEvalTool allows the AI to literally write and execute Javascript code within your host environment. This is the ultimate abstraction for Bots, Apps, and Web Servers.
Instead of hardcoding hundreds of conditions in your code, just inject your framework's instance (e.g., res in Express or bot in Telegram) into the Agent. The AI will analyze the object and dynamically call the right methods!
Example 1: Web Server (Express.js)
import express from 'express';
import { createAgent } from '@astrive-ai/sdk';
const app = express();
const agent = createAgent();
app.post('/api/chat', async (req, res) => {
const { message } = req.body;
// 1. Inject the Express response object into the AI's runtime!
const runtimeTool = agent.getTool('runtime_eval');
runtimeTool.injectContext({ res });
// 2. The AI can now choose to answer normally OR execute code like `res.json(...)`
const response = await agent.chat({
message: message + "\n[System: You can use 'runtime_eval' to call res.json({ data }) directly.]"
});
// 3. Fallback if the AI just returns text instead of executing code
if (!res.headersSent && response.content) {
res.send(response.content);
}
});Example 2: Telegram Bot Integration
Give the AI full control over your Telegram Bot to send complex media and documents seamlessly!
import TelegramBot from 'node-telegram-bot-api';
import { createAgent } from '@astrive-ai/sdk';
const bot = new TelegramBot('YOUR_TOKEN', { polling: true });
const agent = createAgent();
// Inject the global bot instance
const runtimeTool = agent.getTool('runtime_eval');
if (runtimeTool) runtimeTool.injectContext({ bot });
bot.on('message', async (msg) => {
const chatId = msg.chat.id;
// Inject the specific chat session context
if (runtimeTool) runtimeTool.injectContext({ currentChatId: chatId });
const response = await agent.chat({
message: msg.text + `\n[System: You can use 'runtime_eval' and variables 'bot' and 'currentChatId'. Example: await bot.sendVideo(currentChatId, 'url')]`,
sessionId: `tg-user-${msg.from.id}`
});
if (response.content) bot.sendMessage(chatId, response.content);
});🎨 Event-Driven Media with SendMediaTool
Don't want to give the AI execution access? No problem. Use the built-in SendMediaTool combined with Astrive's Event Emitter to capture AI media intent.
// The AI will automatically trigger this event when it wants to deliver media (like downloaded videos/images)
agent.events.on('media:send', async (data) => {
// data contains: { sessionId, mediaType, url, caption }
// You just handle the delivery for your specific platform!
if (data.mediaType === 'video') {
await myPlatform.sendVideo(data.sessionId, data.url, data.caption);
}
});📦 Extending the SDK (Plugins)
You can build plugins to extend the capabilities of Astrive AI.
import { IPlugin, AstriveAI } from '@astrive-ai/sdk';
class MyCustomPlugin implements IPlugin {
name = 'my-custom-plugin';
version = '1.0.0';
async install(agent: AstriveAI): Promise<void> {
// Add custom tools, modify configurations, or listen to events
agent.tool(new MyCustomTool());
}
}
agent.addPlugin(new MyCustomPlugin());📝 License
MIT License
