NodeCache
CORE · interface · Type contract
Synchronous view of the current node's Engine-owned memory. Values retain identity.
Import
ts
import type { NodeCache } from '@jangts/agent-core/engine';js
/** @typedef {import('@jangts/agent-core/engine').NodeCache} NodeCache */Other public entry points:@jangts/agent-core, @jangts/agent-core/engine, @jangts/agent-core/types, @jangts/agent-core/structs.
Definition
ts
interface NodeCacheField structure
| Field | Type | Required | Description |
|---|---|---|---|
get | (key: string, options?: CacheReadOptions) => unknown | Required | See the type definition and usage context. |
has | (key: string) => boolean | Required | See the type definition and usage context. |
set | (key: string, value: unknown) => void | Required | See the type definition and usage context. |
delete | (key: string) => boolean | Required | See the type definition and usage context. |
clear | () => void | Required | See the type definition and usage context. |
Member index
| Member | Purpose |
|---|---|
get | See the overload below for full inputs and outputs. |
has | See the overload below for full inputs and outputs. |
set | See the overload below for full inputs and outputs. |
delete | See the overload below for full inputs and outputs. |
clear | See the overload below for full inputs and outputs. |
Member details
get
ts
NodeCache.get(key: string, options?: CacheReadOptions): unknown| Parameter | Type | Passing | Description |
|---|---|---|---|
key | string | Required | — |
options | CacheReadOptions | undefined | Optional | — |
Optional shapes of Parameter options: choose one shape; required fields for each branch are listed separately.
Branch 1
undefined
Branch 2
| Field | Type | Required | Description |
|---|---|---|---|
nodeId | string | undefined | Optional | Read-only. See the type definition and usage context. |
Returns: unknown.
has
ts
NodeCache.has(key: string): boolean| Parameter | Type | Passing | Description |
|---|---|---|---|
key | string | Required | — |
Returns: boolean.
set
ts
NodeCache.set(key: string, value: unknown): void| Parameter | Type | Passing | Description |
|---|---|---|---|
key | string | Required | — |
value | unknown | Required | — |
Returns: void.
delete
ts
NodeCache.delete(key: string): boolean| Parameter | Type | Passing | Description |
|---|---|---|---|
key | string | Required | — |
Returns: boolean.
clear
ts
NodeCache.clear(): voidNo call parameters.
Returns: void.
Examples
- Workflow: nodes, routes, and partial state updates: Use a single node definition that actually participates in execution to show order, branches, error destinations, and end conditions together.
A single node completes the greeting
Beginner · 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')],
}],
});
console.log(workflow.entryNodeId);
console.log(workflow.describe());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')],
}],
});
console.log(workflow.entryNodeId);
console.log(workflow.describe());Add a validation stage without changing state or the run call
Configuration · Node.js
ts
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
type State = { name: string; answer?: string; error?: string };
const workflow = defineWorkflow<State, string>({
id: 'greeting',
nodes: [
{ id: 'check', description: '检查姓名', startsRound: true,
run: state => ({ error: state.name.trim() ? undefined : '姓名不能为空' }),
routes: [route.toIfError('failure'), route.to('greet')] },
{ id: 'greet', description: '生成问候', provides: ['answer'],
run: state => ({ answer: '你好,' + state.name }), routes: [route.deliver('answer')] },
{ id: 'failure', description: '返回校验提示', requires: ['error'], routes: [route.deliver('error')] },
],
});
console.log(await new AgentCoreEngine({ workflow }).run({ name: 'Ivan' }));js
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
const workflow = defineWorkflow({
id: 'greeting',
nodes: [
{ id: 'check', description: '检查姓名', startsRound: true,
run: state => ({ error: state.name.trim() ? undefined : '姓名不能为空' }),
routes: [route.toIfError('failure'), route.to('greet')] },
{ id: 'greet', description: '生成问候', provides: ['answer'],
run: state => ({ answer: '你好,' + state.name }), routes: [route.deliver('answer')] },
{ id: 'failure', description: '返回校验提示', requires: ['error'], routes: [route.deliver('error')] },
],
});
console.log(await new AgentCoreEngine({ workflow }).run({ name: 'Ivan' }));