Skip to content
中文

NodeAgentCache ​

CORE · interface · Type contract

Async node view. Writes and clear can only address the current partition.

Import ​

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

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

Definition ​

ts
interface NodeAgentCache

Field structure ​

FieldTypeRequiredDescription
get(key: string, options?: AgentCacheOptions & CacheReadOptions) => Promise<unknown>RequiredSee the type definition and usage context.
has(key: string, options?: AgentCacheOptions) => Promise<boolean>RequiredSee the type definition and usage context.
set(key: string, value: unknown, options?: AgentCacheOptions) => Promise<void>RequiredSee the type definition and usage context.
delete(key: string, options?: AgentCacheOptions) => Promise<boolean>RequiredSee the type definition and usage context.
clear(options?: AgentCacheOptions) => Promise<void>RequiredSee the type definition and usage context.

Member index ​

MemberPurpose
getSee the overload below for full inputs and outputs.
hasSee the overload below for full inputs and outputs.
setSee the overload below for full inputs and outputs.
deleteSee the overload below for full inputs and outputs.
clearSee the overload below for full inputs and outputs.

Member details ​

get ​

ts
NodeAgentCache.get(key: string, options?: AgentCacheOptions & CacheReadOptions): Promise<unknown>
ParameterTypePassingDescription
keystringRequired—
options(AgentCacheOptions & CacheReadOptions) | undefinedOptional—

Optional shapes of Parameter options: choose one shape; required fields for each branch are listed separately.

Branch 1

undefined

Branch 2
FieldTypeRequiredDescription
persistenceboolean | undefinedOptionalRead-only. See the type definition and usage context.
nodeIdstring | undefinedOptionalRead-only. See the type definition and usage context.

Returns: Promise<unknown>.

Awaited value: unknown.

has ​

ts
NodeAgentCache.has(key: string, options?: AgentCacheOptions): Promise<boolean>
ParameterTypePassingDescription
keystringRequired—
optionsAgentCacheOptions | undefinedOptional—

Optional shapes of Parameter options: choose one shape; required fields for each branch are listed separately.

Branch 1

undefined

Branch 2
FieldTypeRequiredDescription
persistenceboolean | undefinedOptionalRead-only. See the type definition and usage context.

Returns: Promise<boolean>.

Awaited value: boolean.

set ​

ts
NodeAgentCache.set(key: string, value: unknown, options?: AgentCacheOptions): Promise<void>
ParameterTypePassingDescription
keystringRequired—
valueunknownRequired—
optionsAgentCacheOptions | undefinedOptional—

Optional shapes of Parameter options: choose one shape; required fields for each branch are listed separately.

Branch 1

undefined

Branch 2
FieldTypeRequiredDescription
persistenceboolean | undefinedOptionalRead-only. See the type definition and usage context.

Returns: Promise<void>.

Awaited value: void.

delete ​

ts
NodeAgentCache.delete(key: string, options?: AgentCacheOptions): Promise<boolean>
ParameterTypePassingDescription
keystringRequired—
optionsAgentCacheOptions | undefinedOptional—

Optional shapes of Parameter options: choose one shape; required fields for each branch are listed separately.

Branch 1

undefined

Branch 2
FieldTypeRequiredDescription
persistenceboolean | undefinedOptionalRead-only. See the type definition and usage context.

Returns: Promise<boolean>.

Awaited value: boolean.

clear ​

ts
NodeAgentCache.clear(options?: AgentCacheOptions): Promise<void>
ParameterTypePassingDescription
optionsAgentCacheOptions | undefinedOptional—

Optional shapes of Parameter options: choose one shape; required fields for each branch are listed separately.

Branch 1

undefined

Branch 2
FieldTypeRequiredDescription
persistenceboolean | undefinedOptionalRead-only. See the type definition and usage context.

Returns: Promise<void>.

Awaited value: void.

Examples ​

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' }));

API reference, usage examples and developer guides.