Skip to content
中文

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 AgentCachePort

Field structure ​

FieldTypeRequiredDescription
supportsPersistenceboolean | undefinedOptionalRead-only. See the type definition and usage context.
get(address: AgentCacheAddress) => Promise<unknown>RequiredSee the type definition and usage context.
has(address: AgentCacheAddress) => Promise<boolean>RequiredSee the type definition and usage context.
set(address: AgentCacheAddress, value: unknown) => Promise<void>RequiredSee the type definition and usage context.
delete(address: AgentCacheAddress) => Promise<boolean>RequiredSee the type definition and usage context.
clear(partition: Omit<AgentCacheAddress, "key">) => 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
AgentCachePort.get(address: AgentCacheAddress): Promise<unknown>
ParameterTypePassingDescription
addressAgentCacheAddressRequired—
Fields of address
FieldTypeRequiredDescription
nodeIdstringRequiredRead-only. See the type definition and usage context.
keystringRequiredRead-only. See the type definition and usage context.
persistencebooleanRequiredRead-only. See the type definition and usage context.
signalAbortSignalRequiredRead-only. See the type definition and usage context.

Returns: Promise<unknown>.

Awaited value: unknown.

has ​

ts
AgentCachePort.has(address: AgentCacheAddress): Promise<boolean>
ParameterTypePassingDescription
addressAgentCacheAddressRequired—
Fields of address
FieldTypeRequiredDescription
nodeIdstringRequiredRead-only. See the type definition and usage context.
keystringRequiredRead-only. See the type definition and usage context.
persistencebooleanRequiredRead-only. See the type definition and usage context.
signalAbortSignalRequiredRead-only. See the type definition and usage context.

Returns: Promise<boolean>.

Awaited value: boolean.

set ​

ts
AgentCachePort.set(address: AgentCacheAddress, value: unknown): Promise<void>
ParameterTypePassingDescription
addressAgentCacheAddressRequired—
valueunknownRequired—
Fields of address
FieldTypeRequiredDescription
nodeIdstringRequiredRead-only. See the type definition and usage context.
keystringRequiredRead-only. See the type definition and usage context.
persistencebooleanRequiredRead-only. See the type definition and usage context.
signalAbortSignalRequiredRead-only. See the type definition and usage context.

Returns: Promise<void>.

Awaited value: void.

delete ​

ts
AgentCachePort.delete(address: AgentCacheAddress): Promise<boolean>
ParameterTypePassingDescription
addressAgentCacheAddressRequired—
Fields of address
FieldTypeRequiredDescription
nodeIdstringRequiredRead-only. See the type definition and usage context.
keystringRequiredRead-only. See the type definition and usage context.
persistencebooleanRequiredRead-only. See the type definition and usage context.
signalAbortSignalRequiredRead-only. See the type definition and usage context.

Returns: Promise<boolean>.

Awaited value: boolean.

clear ​

ts
AgentCachePort.clear(partition: Omit<AgentCacheAddress, "key">): Promise<void>
ParameterTypePassingDescription
partitionOmit<AgentCacheAddress, "key">Required—
Fields of partition
FieldTypeRequiredDescription
signalAbortSignalRequiredRead-only. See the type definition and usage context.
nodeIdstringRequiredRead-only. See the type definition and usage context.
persistencebooleanRequiredRead-only. See the type definition and usage context.

Returns: Promise<void>.

Awaited value: void.

Examples ​

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

API reference, usage examples and developer guides.