NodeAgentCache
CORE · interface · Type contract
Async node view. Writes and clear can only address the current partition.
Import
import type { NodeAgentCache } from '@jangts/agent-core/engine';/** @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
interface NodeAgentCacheField structure
| Field | Type | Required | Description |
|---|---|---|---|
get | (key: string, options?: AgentCacheOptions & CacheReadOptions) => Promise<unknown> | Required | See the type definition and usage context. |
has | (key: string, options?: AgentCacheOptions) => Promise<boolean> | Required | See the type definition and usage context. |
set | (key: string, value: unknown, options?: AgentCacheOptions) => Promise<void> | Required | See the type definition and usage context. |
delete | (key: string, options?: AgentCacheOptions) => Promise<boolean> | Required | See the type definition and usage context. |
clear | (options?: AgentCacheOptions) => Promise<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
NodeAgentCache.get(key: string, options?: AgentCacheOptions & CacheReadOptions): Promise<unknown>| Parameter | Type | Passing | Description |
|---|---|---|---|
key | string | Required | — |
options | (AgentCacheOptions & 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 |
|---|---|---|---|
persistence | boolean | undefined | Optional | Read-only. See the type definition and usage context. |
nodeId | string | undefined | Optional | Read-only. See the type definition and usage context. |
Returns: Promise<unknown>.
Awaited value: unknown.
has
NodeAgentCache.has(key: string, options?: AgentCacheOptions): Promise<boolean>| Parameter | Type | Passing | Description |
|---|---|---|---|
key | string | Required | — |
options | AgentCacheOptions | 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 |
|---|---|---|---|
persistence | boolean | undefined | Optional | Read-only. See the type definition and usage context. |
Returns: Promise<boolean>.
Awaited value: boolean.
set
NodeAgentCache.set(key: string, value: unknown, options?: AgentCacheOptions): Promise<void>| Parameter | Type | Passing | Description |
|---|---|---|---|
key | string | Required | — |
value | unknown | Required | — |
options | AgentCacheOptions | 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 |
|---|---|---|---|
persistence | boolean | undefined | Optional | Read-only. See the type definition and usage context. |
Returns: Promise<void>.
Awaited value: void.
delete
NodeAgentCache.delete(key: string, options?: AgentCacheOptions): Promise<boolean>| Parameter | Type | Passing | Description |
|---|---|---|---|
key | string | Required | — |
options | AgentCacheOptions | 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 |
|---|---|---|---|
persistence | boolean | undefined | Optional | Read-only. See the type definition and usage context. |
Returns: Promise<boolean>.
Awaited value: boolean.
clear
NodeAgentCache.clear(options?: AgentCacheOptions): Promise<void>| Parameter | Type | Passing | Description |
|---|---|---|---|
options | AgentCacheOptions | 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 |
|---|---|---|---|
persistence | boolean | undefined | Optional | Read-only. See the type definition and usage context. |
Returns: Promise<void>.
Awaited value: 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
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());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
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' }));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' }));