Package Exports
- @agforge/models
- @agforge/models/cjs/index.js
- @agforge/models/esm/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@agforge/models) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@agforge/models
LLM provider adapters wrapping Vercel AI SDK v6 with streaming and error mapping — the model layer of AgForge SDK.
Overview
@agforge/models provides AiModel, an adapter that bridges any Vercel AI SDK v6 LanguageModel to the AgForge Model interface. It handles:
- Streaming — converts AI SDK streaming responses to
AsyncGenerator<AssistantMessageChunk> - Error mapping — translates provider-specific errors into AgForge error types
- Token tracking — exposes usage metadata (input/output/total tokens)
- Cumulative chunks — each chunk contains complete content from start, not incremental deltas
Install
npm install @agforge/models
# or
pnpm add @agforge/modelsPeer Dependencies
npm install ai @ai-sdk/providerUsage
import { AiModel } from '@agforge/models';
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
const provider = createOpenAICompatible({
name: 'openai',
baseURL: 'https://api.openai.com/v1',
apiKey: process.env.OPENAI_API_KEY,
});
const model = new AiModel({
name: 'gpt-4o',
model: provider.languageModel('gpt-4o'),
maxContextTokens: 200000,
});Use with DefaultAgent:
import { DefaultAgent } from '@agforge/engine';
const agent = new DefaultAgent({ model, tools: [] });
for await (const _ of agent.execute({
message: [{ type: 'text', text: 'Hello!' }],
})) {}Supported Providers
Any provider compatible with Vercel AI SDK v6 works out of the box, including:
- OpenAI (
@ai-sdk/openai) - Anthropic (
@ai-sdk/anthropic) - Google (
@ai-sdk/google) - OpenAI-compatible APIs (
@ai-sdk/openai-compatible) - And more via the AI SDK ecosystem
Related Packages
| Package | Role |
|---|---|
@agforge/core |
Agent protocol, Model interface definition |
@agforge/engine |
DefaultAgent, interceptors, MCP, tools |
@agforge/logger |
Hierarchical logging with scoped config |
@agforge/utils |
Shared utilities (CircuitBreaker, sleep, timeout, etc.) |
License
ISC