Skip to content
English

ErasedTool ​

CORE · interface · 类型合同

Type-erased tool shape the registry executes after parsing at the boundary.

导入 ​

ts
import type { ErasedTool } from '@jangts/agent-core/tools';
js
/** @typedef {import('@jangts/agent-core/tools').ErasedTool} ErasedTool */

其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/tools。

定义 ​

ts
interface ErasedTool

字段结构 ​

字段类型必需说明
idstring必需只读。见类型定义及调用场景。
kindstring必需只读。见类型定义及调用场景。
descriptionstring | undefined可省略只读。Optional here because the erased view does not require model-facing prose.
debugSteps((result: unknown, context: NodeReportingContext) => void) | undefined可省略只读。见类型定义及调用场景。
parseInput(value: unknown) => unknown必需见类型定义及调用场景。
parseOutput(value: unknown) => unknown必需见类型定义及调用场景。
execute(input: unknown, context: ToolExecutionContext) => unknown必需见类型定义及调用场景。

成员目录 ​

成员用途
parseInput完整输入输出见下方重载。
parseOutput完整输入输出见下方重载。
execute完整输入输出见下方重载。

成员详情 ​

parseInput ​

ts
ErasedTool.parseInput(value: unknown): unknown
参数类型传递说明
valueunknown必需—

返回: unknown。

parseOutput ​

ts
ErasedTool.parseOutput(value: unknown): unknown
参数类型传递说明
valueunknown必需—

返回: unknown。

execute ​

ts
ErasedTool.execute(input: unknown, context: ToolExecutionContext): unknown
参数类型传递说明
inputunknown必需—
contextToolExecutionContext必需—
context 的字段
字段类型必需说明
loggerScopedSubFlowLogger | undefined可省略只读。Delegate bound by Core to this actual invocation.
diagnosticsDiagnosticContext | undefined可省略只读。Diagnostic scope of the invocation, when recording is enabled.
mode"sync" | "async"必需只读。Declared execution discipline; mirrors whether the registry accepted an async tool.
invocationIdstring必需只读。Opaque invocation id shared by receipt, events and diagnostics.
signalAbortSignal必需只读。Non-optional cancellation for this invocation.
report(update: import("./execution/workflow.js").WorkflowNodeReport) => void必需Reports progress for the active node; Core supplies the execution identity.
createSubFlowLogger() => SubFlowLogger必需Bound to this context and owned by runtime; repeated calls in one visit return the same instance.

返回: unknown。

使用示例 ​

一个普通步骤即可运行 ​

入门 · Node.js

ts
import { AgentCoreEngine } from '@jangts/agent-core/engine';

const agent = new AgentCoreEngine<string>();
const answer = await agent.run(() => ({ type: 'complete', value: '你好,Core' }));
console.log(answer);
js
import { AgentCoreEngine } from '@jangts/agent-core/engine';
const agent = new AgentCoreEngine();
const answer = await agent.run(() => ({ type: 'complete', value: '你好,Core' }));
console.log(answer);

增加显式 Workflow,仍然调用 run ​

配置 · Node.js

ts
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';

type State = { name: string; answer?: string };
const workflow = defineWorkflow<State, string>({
  id: 'greeting',
  nodes: [{
    id: 'greet', description: '根据本次姓名生成问候', startsRound: true,
    run: state => ({ answer: '你好,' + state.name }),
    routes: [route.deliver('answer')],
  }],
});

const agent = new AgentCoreEngine({ workflow });
console.log(await agent.run({ name: 'Ivan' }));
console.log(await agent.run({ name: '访客' }));
js
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
const workflow = defineWorkflow({
    id: 'greeting',
    nodes: [{
            id: 'greet', description: '根据本次姓名生成问候', startsRound: true,
            run: state => ({ answer: '你好,' + state.name }),
            routes: [route.deliver('answer')],
        }],
});
const agent = new AgentCoreEngine({ workflow });
console.log(await agent.run({ name: 'Ivan' }));
console.log(await agent.run({ name: '访客' }));

相关策略源码 ​

相关定义 ​

接口参考、使用示例与开发指南。