---
title: "AI Kit Core"
description: "Framework-agnostic core — streaming, agent orchestration, state management, and LLM primitives"
canonical: "https://docs.ainative.studio/docs/ai-kit/core"
last-updated: "2026-10-03T21:47:10.764Z"
---

# AI Kit Core

Source: https://docs.ainative.studio/docs/ai-kit/core

> Framework-agnostic core — streaming, agent orchestration, state management, and LLM primitives

# AI Kit Core

Framework-agnostic core providing streaming, agent orchestration, and LLM primitives. Used as the foundation for all framework-specific AI Kit packages.

```bash
npm install @ainative/ai-kit-core
```

## Streaming

### StreamingResponse

Universal streaming that works with any LLM provider:

```typescript
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:

```typescript
import { OpenAIAdapter, AnthropicAdapter, AINativeAdapter } from '@ainative/ai-kit-core';
```

## Agent Orchestration

### Agent

Define an agent with tools and a system prompt:

```typescript
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:

```typescript
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

```typescript
import { generateId, generateShortId } from '@ainative/ai-kit-core';

const id = generateId();        // "msg_a1b2c3d4e5f6g7h8"
const short = generateShortId(); // "x7k2m9"
```

## TypeScript Types

```typescript
import type {
  Agent, AgentConfig, AgentResult,
  StreamingState, StreamingOptions,
  Tool, ToolCall, ToolResult,
  Message, CompletionResponse,
} from '@ainative/ai-kit-core';
```
