AI Kit Core
Framework-agnostic core providing streaming, agent orchestration, and LLM primitives. Used as the foundation for all framework-specific AI Kit packages.
npm install @ainative/ai-kit-core
Streaming
StreamingResponse
Universal streaming that works with any LLM provider:
import { createStreamingResponse, StreamingState } from '@ainative/ai-kit-core';
const stream = createStreamingResponse({
provider: 'ainative', // or 'openai', 'anthropic'
apiKey: 'your-key',
model: 'meta-llama/llama-3.3-70b-instruct',
messages: [{ role: 'user', content: 'Explain quantum computing' }],
});
stream.on('token', (token: string) => {
process.stdout.write(token);
});
stream.on('done', (result) => {
console.log(`\nTokens: ${result.usage.totalTokens}`);
});
stream.on('error', (error) => {
console.error('Stream error:', error);
});
await stream.start();
Provider Adapters
Built-in adapters normalize responses across providers:
import { OpenAIAdapter, AnthropicAdapter, AINativeAdapter } from '@ainative/ai-kit-core';
Agent Orchestration
Agent
Define an agent with tools and a system prompt:
import { Agent, AgentExecutor } from '@ainative/ai-kit-core';
const agent = new Agent({
name: 'data-analyst',
model: 'meta-llama/llama-3.3-70b-instruct',
systemPrompt: 'You are a data analyst. Use tools to answer questions.',
tools: [
{
name: 'query_db',
description: 'Run a SQL query',
parameters: {
type: 'object',
properties: {
sql: { type: 'string', description: 'SQL query to execute' },
},
required: ['sql'],
},
execute: async ({ sql }) => {
// Your implementation
return { rows: [] };
},
},
],
});
AgentExecutor
Run the LLM → Tool → LLM loop:
const executor = new AgentExecutor(agent, {
maxIterations: 10,
onToolCall: (toolName, input) => console.log(`Calling ${toolName}`),
onToolResult: (toolName, result) => console.log(`${toolName} returned`),
});
const result = await executor.run('How many users signed up last week?');
console.log(result.output);
console.log(`Iterations: ${result.iterations}`);
Utilities
ID Generation
import { generateId, generateShortId } from '@ainative/ai-kit-core';
const id = generateId(); // "msg_a1b2c3d4e5f6g7h8"
const short = generateShortId(); // "x7k2m9"
TypeScript Types
import type {
Agent, AgentConfig, AgentResult,
StreamingState, StreamingOptions,
Tool, ToolCall, ToolResult,
Message, CompletionResponse,
} from '@ainative/ai-kit-core';