@ 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
如果您配置了一个没有依赖性的特性,您将会得到一个带有精确安装命令的有帮助的错误消息.
说明: 这个
dextoCLI软件包包括所有可选的依赖性. 只有在使用@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/ 页面存档备份,存于互联网档案馆
链接
- 文档 : https://cli.dexto.ai/ 互联网档案馆的存檔,存档日期2013-12-02
- 配置指南 : https://cli.dexto.ai/docs/ 类别/指针/
- API 参考 : https://cli.dexto.ai/api/ 页面存档备份,存于互联网档案馆
许可证
弹性许可证2.0. 详情见LICENSE仓库.