@dexto/core

中文文档
1.17.0发布于 2026/11/10TypeScriptESM + CJS近 30 天下载 1.8万

Dexto Agent SDK在程序上用于构建代理应用. 这个软件包赋予了Dexto CLI 的功能,让你在自己的应用程序中嵌入相同的代理运行时间.

中文使用文档
文档目录12 节
  1. 安装
  2. 可选的依赖关系
  3. 快速启动
  4. 正在启动服务器
  5. 会话管理
  6. LLM 管理
  7. MCP 管理器
  8. 代理对代理代表团
  9. 遥测
  10. 锁定器
  11. 链接
  12. 许可证

@ dexto/ core (帮助)

Dexto Agent SDK在程序上用于构建代理应用. 这个软件包赋予了Dexto CLI 的功能,让你在自己的应用程序中嵌入相同的代理运行时间.

安装

npm install @dexto/core

可选的依赖关系

一些特性需要额外的包. 只安装您需要的 :

# Telemetry (OpenTelemetry distributed tracing)
npm install @opentelemetry/sdk-node @opentelemetry/auto-instrumentations-node \
  @opentelemetry/resources @opentelemetry/semantic-conventions \
  @opentelemetry/sdk-trace-base @opentelemetry/exporter-trace-otlp-http

# For gRPC telemetry export protocol
npm install @opentelemetry/exporter-trace-otlp-grpc

# Storage backends
npm install better-sqlite3  # SQLite database
npm install pg              # PostgreSQL database
npm install ioredis         # Redis cache

# TypeScript plugin support
npm install tsx

如果您配置了一个没有依赖性的特性,您将会得到一个带有精确安装命令的有帮助的错误消息.

说明: 这个 dexto CLI软件包包括所有可选的依赖性. 只有在使用 @dexto/core 直接作为图书馆.

快速启动

import { DextoAgent } from '@dexto/core';

// Create and start agent
const agent = new DextoAgent({
  llm: {
    provider: 'openai',
    model: 'gpt-5-mini',
    apiKey: process.env.OPENAI_API_KEY
  }
});
await agent.start();

// Create a session for the conversation
const session = await agent.createSession();

// Use generate() for simple request/response
const response = await agent.generate('What is TypeScript?', session.id);
console.log(response.content);

// Conversations maintain context within a session
await agent.generate('Write a haiku about it', session.id);
await agent.generate('Make it funnier', session.id);

// Multimodal: send images or files
await agent.generate([
  { type: 'text', text: 'Describe this image' },
  { type: 'image', image: base64Data, mimeType: 'image/png' }
], session.id);

// Streaming for real-time UIs
for await (const event of await agent.stream('Write a story', session.id)) {
  if (event.name === 'llm:chunk') process.stdout.write(event.content);
}

await agent.stop();

见 Dexto 代理 SDK 文件 用于多模式内容、流线、MCP工具和高级特性.


正在启动服务器

在程序上启动一个 Dexto 服务器, 以曝光 REST 和 SSE 流媒体 API 以交互和管理您的代理后端 .

import { DextoAgent } from '@dexto/core';
import { startHonoApiServer } from 'dexto';

// Create and configure agent
const agent = new DextoAgent({
  llm: {
    provider: 'openai',
    model: 'gpt-5-mini',
    apiKey: process.env.OPENAI_API_KEY
  },
  mcpServers: {
    filesystem: {
      type: 'stdio',
      command: 'npx',
      args: ['-y', '@modelcontextprotocol/server-filesystem', '.']
    }
  }
});

// Start server on port 3001
const { server } = await startHonoApiServer(agent, 3001);

console.log('Dexto server running at http://localhost:3001');
// Server provides REST API and SSE streaming endpoints
// POST /api/message - Send messages
// GET /api/sessions - List sessions
// See cli.dexto.ai/api/rest/ for all endpoints

这开始一个HTTP服务器,配备了完整的REST和SSE API,能够与网络前端,webhooks等服务集成. 见 REST API 文档 用于可用的终点.

会话管理

创建和管理多个持续存储的对话会话.

const agent = new DextoAgent(config);
await agent.start();

// Create and manage sessions
const session = await agent.createSession('user-123');
await agent.generate('Hello, how can you help me?', session.id);

// List and manage sessions
const sessions = await agent.listSessions();
const sessionHistory = await agent.getSessionHistory('user-123');
await agent.deleteSession('user-123');

// Search across conversations
const results = await agent.searchMessages('bug fix', { limit: 10 });

LLM 管理

在模型和提供者之间动态切换.

// Get current configuration
const currentLLM = agent.getCurrentLLMConfig();

// Switch models (provider inferred automatically)
await agent.switchLLM({ model: 'gpt-5-mini' });
await agent.switchLLM({ model: 'claude-sonnet-4-5-20250929' });

// Switch model for a specific session id 1234
await agent.switchLLM({ model: 'gpt-5-mini' }, '1234')

// Get supported providers and models
const providers = agent.getSupportedProviders();
const models = agent.getSupportedModels();
const openaiModels = agent.getSupportedModelsForProvider('openai');

MCP 管理器

对于高级MCP服务器管理,直接使用MCPManager.

import { MCPManager } from '@dexto/core';

const manager = new MCPManager();

// Connect to MCP servers
await manager.connectServer('filesystem', {
  type: 'stdio',
  command: 'npx',
  args: ['-y', '@modelcontextprotocol/server-filesystem', '.']
});

// Access tools, prompts, and resources
const tools = await manager.getAllTools();
const prompts = await manager.getAllPrompts();
const resources = await manager.getAllResources();

// Execute tools
const result = await manager.executeTool('readFile', { path: './README.md' });

await manager.disconnectAll();

代理对代理代表团

使用内置的符合 A2A 要求的代理代理代理代理任务 delegate_to_url 工具.

import { builtinToolsFactory } from '@dexto/tools-builtins';

const tools = builtinToolsFactory.create({
  type: 'builtin-tools',
  enabledTools: ['delegate_to_url'],
});

const agent = new DextoAgent({
  llm: { /* ... */ },
  logger,   // provide a per-agent logger instance
  storage,  // provide cache/database/blob implementations
  tools,
  permissions: { mode: 'auto-approve' }
});
await agent.start();

const session = await agent.createSession();

// Delegate via natural language
await agent.generate(`
  Please delegate this task to the PDF analyzer agent at http://localhost:3001:
  "Extract all tables from the Q4 sales report"
`, session.id);

// Or call the tool directly
await agent.executeTool('delegate_to_url', {
  url: 'http://localhost:3001',
  message: 'Extract all tables from the Q4 sales report',
});

配置 (YAML) :

tools:
  - type: builtin-tools
    enabledTools:
      - delegate_to_url

它所提供的:

  • 了解代理 URL 的点对点代表团
  • A2A议定书 v0.3.0 符合(JSON-RPC运输)
  • 用于状态多回合对话的会话管理
  • 自动发现端点(/v1/jsonrpc,/jsonrpc)
  • 超时处理和错误恢复

使用大小写 :

  • 具有已知代理 URL 的多代理系统
  • 授权给专门机构
  • 建设代理工作流程和管道
  • 测试代理与代理通信

遥测

已建成的OpenTeleometry分布式追踪可观察性.

const agent = new DextoAgent({
  llm: { /* ... */ },
  telemetry: {
    enabled: true,
    serviceName: 'my-agent',
    export: {
      type: 'otlp',
      endpoint: 'http://localhost:4318/v1/traces'
    }
  }
});

自动追踪代理操作, LLM 调用符号使用,以及工具执行. 见 src/telemetry/README.md 详细情况.

锁定器

多运输记录系统(v2),设有控制台,文档和远程运输. 在代理 YAML 中配置 :

logger:
  level: info  # error | warn | info | debug | silly
  transports:
    - type: console
      colorize: true
    - type: file
      path: ./logs/agent.log
      maxSize: 10485760
      maxFiles: 5

CLI 在 ~/.dexto/logs/<agent-id>.log。参见 src/logger/v2/。 。 。 .

所有方法见DextoAgent API参考: https://cli.dexto.ai/api/dexto-agent/ 页面存档备份,存于互联网档案馆


许可证

弹性许可证2.0. 详情见LICENSE仓库.

版本与发布记录

@dexto/core 共发布 111 个版本,首次发布于 2025/09/12;过去 12 个月发布了 98 个版本。

版本发布日期距今
1.17.0latest2026/11/102 天前
1.16.62026/11/093 天前
1.16.52026/11/093 天前
1.16.42026/11/093 天前
1.16.32026/11/093 天前
1.16.22026/11/093 天前

其他发布通道:next → 1.15.0-beta.4。

关于 @dexto/core 的常见问题

@dexto/core 是什么?

Dexto Agent SDK在程序上用于构建代理应用. 这个软件包赋予了Dexto CLI 的功能,让你在自己的应用程序中嵌入相同的代理运行时间.

如何安装 @dexto/core?

在项目目录运行 npm install @dexto/core,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:zod(^4.3.6)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dexto/core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dexto/core 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dexto/core 可以商用吗?

@dexto/core 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@dexto/core 的下载量有多少?

根据 npm 官方下载统计,@dexto/core 在 2026/10/12 – 2026/11/10 这 30 天内被下载 18,489 次,日均约 616 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dexto/core 还在维护吗?

最新版本 1.17.0 发布于 2026/11/10(2 天前);至今共发布 111 个版本,其中过去 12 个月发布了 98 个;首次发布于 2025/09/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。