di-framework/ai
TypeScript libraries for building AI applications with chat models, tools, memory, retrieval, MCP, and agents. Use the fluent APIs directly or integrate them with @di-framework/core dependency injection.
Power your agent
คำสั่งของผู้เผยแพร่เอง ไม่ใช่เอนด์พอยต์ของ PlugMCP
Host a copy with our keys and logs.
npx -y @di-framework/[email protected]Claude Code ไม่มีลิงก์ติดตั้งสำหรับคำสั่งแบบโลคัล ให้คัดลอกคำสั่งด้านล่างแล้วรันในเทอร์มินัล
claude mcp add di-framework-ai -- npx -y @di-framework/ai@6.0.3รันในเทอร์มินัล
{ "mcpServers": { "di-framework-ai": { "command": "npx", "args": [ "-y", "@di-framework/[email protected]" ] } }}claude_desktop_config.json
URL แบบรีโมตหรือคำสั่งบนเครื่องของคุณ? การติดตั้งสองแบบต่างกันอย่างไร
รันบน PlugMCP
A new server you create. It is not this listing's official endpoint. Use the publisher install when you want their URL and their credentials.
เปิดจากผู้เผยแพร่
TypeScript libraries for building AI applications with chat models, tools, memory, retrieval, MCP, and agents. Use the fluent APIs directly or integrate them with @di-framework/core dependency injection.
Declarative library for building AI applications
| Documentation |
|---|
@di-framework/ai | Chat clients, providers, tools, memory, RAG, MCP, workflows, and A2A | AI README |
@di-framework/ai-utils | Agent Skills (SKILL.md), repository instructions, file and shell tools, and skill discovery | AI utilities README |
@di-framework/ml | ONNX Runtime Web session for a di-ml checkpoint | ML README |
The examples use Bun to run TypeScript directly. Both packages export TypeScript source; other runtimes need compatible TypeScript tooling.
bun add @di-framework/ai@^6 @di-framework/core@^5 @di-framework/auth@^5
bun add --dev typescript@^5
# Add skills and agent utilities when needed:
bun add @di-framework/ai-utils@^6
You can also install these packages with npm. The first release from this repository is 6.0.0; the core and auth peers remain on published 5.x packages.
The di-ml CLI is a prerelease of @di-framework/ml, one version per OS and architecture: npm install -g @di-framework/[email protected]. See the ML README.
Save this as chat.ts:
import { ChatClient, createChatModel } from '@di-framework/ai';
const client = ChatClient.builder(createChatModel())
.defaultSystem('You are a concise, helpful assistant.')
.build();
const answer = await client
.prompt('Explain dependency injection in two sentences.')
.call()
.content();
console.log(answer);
Set your provider's API key in the environment, then run:
# Requires OPENAI_API_KEY:
PROVIDER=openai AUTH=api bun chat.ts
# Or, with ANTHROPIC_API_KEY:
PROVIDER=anthropic AUTH=api bun chat.ts
createChatModel() reads PROVIDER, AUTH, and optional MODEL. You can select them explicitly with createChatModel({ provider: 'anthropic', auth: 'api', model: 'your-model-id' }). See the provider documentation for supported routes and subscription setup.
Using the same client, replace the call above with:
for await (const content of client.prompt('Explain dependency injection.').stream().content()) {
console.log(content);
}
Each value contains the accumulated response text so far, suitable for replacing the displayed answer as it arrives.
Describe a callback with a JSON Schema. The client handles tool requests and feeds results back to the model before returning the final answer.
import { ChatClient, createChatModel, functionToolCallback } from '@di-framework/ai';
const add = functionToolCallback<{ a: number; b: number }, number>({
name: 'add',
description: 'Add two numbers.',
inputSchema: {
type: 'object',
properties: { a: { type: 'number' }, b: { type: 'number' } },
required: ['a', 'b'],
additionalProperties: false,
},
call: ({ a, b }) => a + b,
});
const client = ChatClient.builder(createChatModel()).defaultTools(add).build();
console.log(await client.prompt('Use add to calculate 19 + 23.').call().content());
Run this and the following model-backed examples with the same provider environment as the quick start.
ChatAgent wraps a client with reusable instructions, tools, and optional memory. Supply the same conversation ID for related turns and a different ID for each independent conversation.
import { ChatAgent, createChatModel, MessageWindowChatMemory } from '@di-framework/ai';
const agent = ChatAgent.create({
chatModel: createChatModel(),
system: 'You are a helpful assistant.',
memory: MessageWindowChatMemory.builder().maxMessages(20).build(),
});
await agent.chat('My name is Ada.', { conversationId: 'session-1' });
const reply = await agent.chat('What is my name?', { conversationId: 'session-1' });
console.log(reply.content);
This memory lives in the current process. The message window drops older turns as it fills.
Install @di-framework/ai-utils, then create .agents/skills/code-reviewer/SKILL.md in your project:
---
name: code-reviewer
description: Review TypeScript code for correctness. Use when asked to review code.
---
# Code review
1. Read the requested file.
2. Identify correctness issues and explain their impact.
3. Suggest a concrete fix for each issue.
Run this from the project directory, replacing src/index.ts with a file to review:
import { createChatModel } from '@di-framework/ai';
import { SkillsAgent } from '@di-framework/ai-utils';
const agent = SkillsAgent.builder()
.chatModel(createChatModel())
.system('Help review TypeScript code. Use the code-reviewer skill when reviewing.')
.workspace(process.cwd())
.addSkillsDirectory('.agents/skills')
.build();
const reply = await agent.chat('Review src/index.ts.');
console.log(reply.content);
Skills expose descriptions first and load their full instructions when activated. The toolbox includes file-reading tools; writing, editing, and shell execution are opt-in. See the utilities documentation for toolbox configuration, instruction discovery, and skill catalogs.
Use FakeChatModel for a fixed response, or ScriptedChatModel for multi-turn and tool-calling tests:
import { ChatClient, FakeChatModel } from '@di-framework/ai';
const model = new FakeChatModel('Hello, Ada!');
const client = ChatClient.create(model);
console.log(await client.prompt('Say hello to Ada.').call().content());
// Hello, Ada!
console.log(model.calls.length);
// 1
From the repository root:
bun install
bun test
bun run typecheck
bun run lint
Run a package's tests with bun test packages/ai/tests or bun test packages/ai-utils/tests. Train an ONNX workspace with the di-ml binary (cargo run -p di-ml-cli -- <workspace>). The workspace uses published core/auth peers. The CLI host (di-framework agent, di-framework skills) lives in the separate di-framework/di-framework repository.
Licensed under either MIT or Apache-2.0, at your option.
Declarative library for building AI applications
{ "mcpServers": { "di-framework-ai": { "command": "npx", "args": [ "-y", "@di-framework/[email protected]" ] } }}เครื่องมือ
ยังไม่มีรายการเครื่องมือ เซิร์ฟเวอร์แบบรีโมตจะได้รายการหลังการตรวจสอบสถานะครั้งแรก
FAQ
คัดลอกคอนฟิก stdio สำหรับ Cursor, Claude Desktop, Claude Code หรือ VS Code ได้ในหน้านี้ คอนฟิกนี้ใช้การติดตั้งของผู้เผยแพร่ ไม่ใช่พร็อกซีของ PlugMCP
ระเบียนนี้ไม่ได้ระบุตัวแปรสภาพแวดล้อมที่จำเป็น
@di Framework/ai ทำงานแบบโลคัลผ่าน stdio
ตรวจสอบล่าสุดเมื่อ 2026-10-28 Declarative library for building AI applications