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 ErasedToolField structure
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Read-only. See the type definition and usage context. |
kind | string | Required | Read-only. See the type definition and usage context. |
description | string | undefined | Optional | Read-only. Optional here because the erased view does not require model-facing prose. |
debugSteps | ((result: unknown, context: NodeReportingContext) => void) | undefined | Optional | Read-only. See the type definition and usage context. |
parseInput | (value: unknown) => unknown | Required | See the type definition and usage context. |
parseOutput | (value: unknown) => unknown | Required | See the type definition and usage context. |
execute | (input: unknown, context: ToolExecutionContext) => unknown | Required | See the type definition and usage context. |
Member index
| Member | Purpose |
|---|---|
parseInput | See the overload below for full inputs and outputs. |
parseOutput | See the overload below for full inputs and outputs. |
execute | See the overload below for full inputs and outputs. |
Member details
parseInput
ts
ErasedTool.parseInput(value: unknown): unknown| Parameter | Type | Passing | Description |
|---|---|---|---|
value | unknown | Required | — |
Returns: unknown.
parseOutput
ts
ErasedTool.parseOutput(value: unknown): unknown| Parameter | Type | Passing | Description |
|---|---|---|---|
value | unknown | Required | — |
Returns: unknown.
execute
ts
ErasedTool.execute(input: unknown, context: ToolExecutionContext): unknown| Parameter | Type | Passing | Description |
|---|---|---|---|
input | unknown | Required | — |
context | ToolExecutionContext | Required | — |
Fields of context
| Field | Type | Required | Description |
|---|---|---|---|
logger | ScopedSubFlowLogger | undefined | Optional | Read-only. Delegate bound by Core to this actual invocation. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Diagnostic scope of the invocation, when recording is enabled. |
mode | "sync" | "async" | Required | Read-only. Declared execution discipline; mirrors whether the registry accepted an async tool. |
invocationId | string | Required | Read-only. Opaque invocation id shared by receipt, events and diagnostics. |
signal | AbortSignal | Required | Read-only. Non-optional cancellation for this invocation. |
report | (update: import("./execution/workflow.js").WorkflowNodeReport) => void | Required | Reports progress for the active node; Core supplies the execution identity. |
createSubFlowLogger | () => SubFlowLogger | Required | Bound to this context and owned by runtime; repeated calls in one visit return the same instance. |
Returns: unknown.
Examples
- Agent: run first, then bind tools and dependencies step by step: The Engine executes a bounded loop; after a Workflow is bound, each run only receives the data that changed in state.
- Reusing a base Workflow and Agent branches: add preserves the old Workflow and produces a new combined Workflow; fork inherits existing bindings and the branch origin.
- Bind once, multiple models per run, and switching across runs: Provide stable model configuration at construction; requests select by configuration ID instead of injecting a Provider repeatedly.
- Real tool invocation and in-request runtime: Core registers and executes real tools and returns receipts carrying an invocation; business authorization is owned by the implementation registered by the App.
- Decorators: complete handlers and existing host methods: Classes construct definitions automatically; methods bind the real host. Outputs still use original define, constructor and bind contracts.
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: '访客' }));Related policy source
- Execution implementation of the bounded loop, commit, and cancellation
- Check order for tool input, execution, output, and late results