Skip to content
中文

ErasedTool ​

CORE · interface · Type contract

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

Import ​

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

Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/tools.

Definition ​

ts
interface ErasedTool

Field structure ​

FieldTypeRequiredDescription
idstringRequiredRead-only. See the type definition and usage context.
kindstringRequiredRead-only. See the type definition and usage context.
descriptionstring | undefinedOptionalRead-only. Optional here because the erased view does not require model-facing prose.
debugSteps((result: unknown, context: NodeReportingContext) => void) | undefinedOptionalRead-only. See the type definition and usage context.
parseInput(value: unknown) => unknownRequiredSee the type definition and usage context.
parseOutput(value: unknown) => unknownRequiredSee the type definition and usage context.
execute(input: unknown, context: ToolExecutionContext) => unknownRequiredSee the type definition and usage context.

Member index ​

MemberPurpose
parseInputSee the overload below for full inputs and outputs.
parseOutputSee the overload below for full inputs and outputs.
executeSee the overload below for full inputs and outputs.

Member details ​

parseInput ​

ts
ErasedTool.parseInput(value: unknown): unknown
ParameterTypePassingDescription
valueunknownRequired—

Returns: unknown.

parseOutput ​

ts
ErasedTool.parseOutput(value: unknown): unknown
ParameterTypePassingDescription
valueunknownRequired—

Returns: unknown.

execute ​

ts
ErasedTool.execute(input: unknown, context: ToolExecutionContext): unknown
ParameterTypePassingDescription
inputunknownRequired—
contextToolExecutionContextRequired—
Fields of context
FieldTypeRequiredDescription
loggerScopedSubFlowLogger | undefinedOptionalRead-only. Delegate bound by Core to this actual invocation.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Diagnostic scope of the invocation, when recording is enabled.
mode"sync" | "async"RequiredRead-only. Declared execution discipline; mirrors whether the registry accepted an async tool.
invocationIdstringRequiredRead-only. Opaque invocation id shared by receipt, events and diagnostics.
signalAbortSignalRequiredRead-only. Non-optional cancellation for this invocation.
report(update: import("./execution/workflow.js").WorkflowNodeReport) => voidRequiredReports progress for the active node; Core supplies the execution identity.
createSubFlowLogger() => SubFlowLoggerRequiredBound to this context and owned by runtime; repeated calls in one visit return the same instance.

Returns: unknown.

Examples ​

A single ordinary step is enough to run ​

Beginner · 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);

Add an explicit Workflow and still call run ​

Configuration · 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: '访客' }));

API reference, usage examples and developer guides.