AgentCachePort
CORE · interface · Type contract
App-owned storage. Capacity, expiry, serialization and user isolation belong to the App.
Import
ts
import type { AgentCachePort } from '@jangts/agent-core/engine';js
/** @typedef {import('@jangts/agent-core/engine').AgentCachePort} AgentCachePort */Other public entry points:@jangts/agent-core, @jangts/agent-core/engine, @jangts/agent-core/types, @jangts/agent-core/structs.
Definition
ts
interface AgentCachePortField structure
| Field | Type | Required | Description |
|---|---|---|---|
supportsPersistence | boolean | undefined | Optional | Read-only. See the type definition and usage context. |
get | (address: AgentCacheAddress) => Promise<unknown> | Required | See the type definition and usage context. |
has | (address: AgentCacheAddress) => Promise<boolean> | Required | See the type definition and usage context. |
set | (address: AgentCacheAddress, value: unknown) => Promise<void> | Required | See the type definition and usage context. |
delete | (address: AgentCacheAddress) => Promise<boolean> | Required | See the type definition and usage context. |
clear | (partition: Omit<AgentCacheAddress, "key">) => 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
ts
AgentCachePort.get(address: AgentCacheAddress): Promise<unknown>| Parameter | Type | Passing | Description |
|---|---|---|---|
address | AgentCacheAddress | Required | — |
Fields of address
| Field | Type | Required | Description |
|---|---|---|---|
nodeId | string | Required | Read-only. See the type definition and usage context. |
key | string | Required | Read-only. See the type definition and usage context. |
persistence | boolean | Required | Read-only. See the type definition and usage context. |
signal | AbortSignal | Required | Read-only. See the type definition and usage context. |
Returns: Promise<unknown>.
Awaited value: unknown.
has
ts
AgentCachePort.has(address: AgentCacheAddress): Promise<boolean>| Parameter | Type | Passing | Description |
|---|---|---|---|
address | AgentCacheAddress | Required | — |
Fields of address
| Field | Type | Required | Description |
|---|---|---|---|
nodeId | string | Required | Read-only. See the type definition and usage context. |
key | string | Required | Read-only. See the type definition and usage context. |
persistence | boolean | Required | Read-only. See the type definition and usage context. |
signal | AbortSignal | Required | Read-only. See the type definition and usage context. |
Returns: Promise<boolean>.
Awaited value: boolean.
set
ts
AgentCachePort.set(address: AgentCacheAddress, value: unknown): Promise<void>| Parameter | Type | Passing | Description |
|---|---|---|---|
address | AgentCacheAddress | Required | — |
value | unknown | Required | — |
Fields of address
| Field | Type | Required | Description |
|---|---|---|---|
nodeId | string | Required | Read-only. See the type definition and usage context. |
key | string | Required | Read-only. See the type definition and usage context. |
persistence | boolean | Required | Read-only. See the type definition and usage context. |
signal | AbortSignal | Required | Read-only. See the type definition and usage context. |
Returns: Promise<void>.
Awaited value: void.
delete
ts
AgentCachePort.delete(address: AgentCacheAddress): Promise<boolean>| Parameter | Type | Passing | Description |
|---|---|---|---|
address | AgentCacheAddress | Required | — |
Fields of address
| Field | Type | Required | Description |
|---|---|---|---|
nodeId | string | Required | Read-only. See the type definition and usage context. |
key | string | Required | Read-only. See the type definition and usage context. |
persistence | boolean | Required | Read-only. See the type definition and usage context. |
signal | AbortSignal | Required | Read-only. See the type definition and usage context. |
Returns: Promise<boolean>.
Awaited value: boolean.
clear
ts
AgentCachePort.clear(partition: Omit<AgentCacheAddress, "key">): Promise<void>| Parameter | Type | Passing | Description |
|---|---|---|---|
partition | Omit<AgentCacheAddress, "key"> | Required | — |
Fields of partition
| Field | Type | Required | Description |
|---|---|---|---|
signal | AbortSignal | Required | Read-only. See the type definition and usage context. |
nodeId | string | Required | Read-only. See the type definition and usage context. |
persistence | boolean | Required | Read-only. See the type definition and usage context. |
Returns: Promise<void>.
Awaited value: void.
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