JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 147
  • Score
    100M100P100Q54944F
  • License ISC

DefaultAgent with built-in interceptors, MCP client, tool factory, context compression, and error hierarchy for AgForge SDK

Package Exports

  • @agforge/engine
  • @agforge/engine/cjs/index.js
  • @agforge/engine/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/engine) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@agforge/engine

DefaultAgent with built-in interceptors, MCP client, tool factory, context compression, and error hierarchy — the capability layer of AgForge SDK.

Overview

@agforge/engine provides the full implementation on top of @agforge/core:

  • DefaultAgent — production-ready agent with auto-assembled built-in interceptors
  • Built-in interceptors — tracing, compression, error limits, message sanitization, system reminder, MCP, and more
  • MCP client — full Model Context Protocol integration with auto-reconnect, heartbeat, and circuit breaker
  • Tool factorycreateTool with Zod schema validation and dual-channel output
  • Context compression — threshold-based strategy + LLM summary compressor
  • Message sanitization — auto-fix rules for malformed message sequences
  • Error hierarchy — structured error types for agent lifecycle
  • Execution locker — per-tool serial locking for concurrent safety
  • Permission manager — URL-based permission control
  • Skill system — declarative skill composition
  • System reminder — automatic system prompt injection

Install

npm install @agforge/engine
# or
pnpm add @agforge/engine

Usage

Basic Agent

import { DefaultAgent } from '@agforge/engine';
import { AiModel } from '@agforge/models';

const agent = new DefaultAgent({ model, tools: [] });

for await (const _ of agent.execute({
  message: [{ type: 'text', text: 'Hello!' }],
})) {}

Creating Tools

import { createTool } from '@agforge/engine';
import { z } from 'zod';

const weatherTool = createTool({
  name: 'get_weather',
  description: 'Get the current weather for a given city.',
  parameters: z.object({
    city: z.string().describe('The city name'),
  }),
})(() => ({
  execute: async function* (params) {
    const data = await fetchWeather(params.city);
    yield {
      structResult: { temperature: data.temp, humidity: data.humidity },
      llmMessage: { type: 'text', text: `${params.city}: ${data.temp}°C` },
      isCompleted: true,
    };
  },
  stop: async () => {},
}));

MCP Integration

import { McpClient } from '@agforge/engine';

const client = new McpClient({
  name: 'my-mcp-server',
  transport: {
    type: 'stdio',
    command: 'npx',
    args: ['-y', '@modelcontextprotocol/server-filesystem', '/path'],
  },
  reconnect: { enabled: true, maxAttempts: 5 },
});

await client.connect();
const agent = new DefaultAgent({ model, tools: [], mcpClients: [client] });

Context Compression

import { ThresholdCompressionStrategy, LlmSummaryCompressor } from '@agforge/engine';

const agent = new DefaultAgent({
  model,
  tools: [],
  compression: {
    compressor: new LlmSummaryCompressor({ model: summaryModel }),
    strategy: new ThresholdCompressionStrategy({
      asyncThreshold: 0.5,
      syncThreshold: 0.7,
      preserveRecentRounds: 5,
    }),
  },
});

Message Sanitization

const agent = new DefaultAgent({
  model,
  tools: [],
  messageSanitize: 'fix', // 'fix' (default) | 'warn' | 'off'
});
Package Role
@agforge/core Agent protocol, interfaces, execution skeleton
@agforge/models LLM provider adapters (Vercel AI SDK v6)
@agforge/logger Hierarchical logging with scoped config
@agforge/utils Shared utilities (CircuitBreaker, sleep, timeout, etc.)

License

ISC