@jangts/agent-core 0.2.1 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/development/docs/api/reference.md +290 -257
- package/development/docs/api/workflow.en.md +10 -0
- package/development/docs/api/workflow.md +22 -0
- package/development/skills/agent-core-app/SKILL.md +4 -0
- package/dist/cjs/execution/cache.js +162 -0
- package/dist/cjs/execution/engine.js +10 -0
- package/dist/cjs/kits/vector-search.js +4 -7
- package/dist/cjs/structs/execution/cache.js +6 -0
- package/dist/esm/execution/cache.d.ts +20 -0
- package/dist/esm/execution/cache.js +156 -0
- package/dist/esm/execution/engine.d.ts +5 -0
- package/dist/esm/execution/engine.js +10 -0
- package/dist/esm/kits/vector-search.js +4 -7
- package/dist/esm/structs/execution/cache.d.ts +54 -0
- package/dist/esm/structs/execution/cache.js +5 -0
- package/dist/esm/structs/execution/engine.d.ts +6 -1
- package/dist/esm/structs/execution/workflow.d.ts +2 -1
- package/dist/esm/structs/index.d.ts +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-partitioned cache contracts. Engine memory is synchronous; service-owned storage is
|
|
3
|
+
* asynchronous and explicitly selects volatile or persistent space. Neither is workflow state.
|
|
4
|
+
*/
|
|
5
|
+
/** Optional Engine memory bounds; TTL is measured from the latest write. */
|
|
6
|
+
export interface EngineCacheOptions {
|
|
7
|
+
readonly maxEntries?: number;
|
|
8
|
+
readonly ttlMs?: number;
|
|
9
|
+
}
|
|
10
|
+
/** Only reads may name another node. Partition names are not authorization boundaries. */
|
|
11
|
+
export interface CacheReadOptions {
|
|
12
|
+
readonly nodeId?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Synchronous view of the current node's Engine-owned memory. Values retain identity. */
|
|
15
|
+
export interface NodeCache {
|
|
16
|
+
get(key: string, options?: CacheReadOptions): unknown;
|
|
17
|
+
has(key: string): boolean;
|
|
18
|
+
set(key: string, value: unknown): void;
|
|
19
|
+
delete(key: string): boolean;
|
|
20
|
+
clear(): void;
|
|
21
|
+
}
|
|
22
|
+
/** Persistent and volatile storage are independent; there is no implicit fallback or mirroring. */
|
|
23
|
+
export interface AgentCacheOptions {
|
|
24
|
+
readonly persistence?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** Exact immutable address passed to the App port, including cancellation for this visit. */
|
|
27
|
+
export interface AgentCacheAddress {
|
|
28
|
+
readonly nodeId: string;
|
|
29
|
+
readonly key: string;
|
|
30
|
+
readonly persistence: boolean;
|
|
31
|
+
readonly signal: AbortSignal;
|
|
32
|
+
}
|
|
33
|
+
/** App-owned storage. Capacity, expiry, serialization and user isolation belong to the App. */
|
|
34
|
+
export interface AgentCachePort {
|
|
35
|
+
readonly supportsPersistence?: boolean;
|
|
36
|
+
get(address: AgentCacheAddress): Promise<unknown>;
|
|
37
|
+
has(address: AgentCacheAddress): Promise<boolean>;
|
|
38
|
+
set(address: AgentCacheAddress, value: unknown): Promise<void>;
|
|
39
|
+
delete(address: AgentCacheAddress): Promise<boolean>;
|
|
40
|
+
clear(partition: Omit<AgentCacheAddress, 'key'>): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
/** Async node view. Writes and clear can only address the current partition. */
|
|
43
|
+
export interface NodeAgentCache {
|
|
44
|
+
get(key: string, options?: AgentCacheOptions & CacheReadOptions): Promise<unknown>;
|
|
45
|
+
has(key: string, options?: AgentCacheOptions): Promise<boolean>;
|
|
46
|
+
set(key: string, value: unknown, options?: AgentCacheOptions): Promise<void>;
|
|
47
|
+
delete(key: string, options?: AgentCacheOptions): Promise<boolean>;
|
|
48
|
+
clear(options?: AgentCacheOptions): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
/** Cache access shared by workflow visits and the low-level $step loop. */
|
|
51
|
+
export interface CacheContext {
|
|
52
|
+
readonly cache: NodeCache;
|
|
53
|
+
readonly agentCache?: NodeAgentCache;
|
|
54
|
+
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* Exports: `LoopEvent`, `StepOutcome`, `CoreStep`, `AgentCoreEngineOptions`.
|
|
9
9
|
*/
|
|
10
10
|
import type { ExecutionContext, ExecutionOptions, MaybePromise } from '../common.js';
|
|
11
|
+
import type { CacheContext, EngineCacheOptions, AgentCachePort } from './cache.js';
|
|
11
12
|
/** Progress fact for one loop round, correlated with the enclosing diagnostics span. */
|
|
12
13
|
export interface LoopEvent {
|
|
13
14
|
/** Unique id of this fact. */
|
|
@@ -31,9 +32,13 @@ export type StepOutcome<Value> =
|
|
|
31
32
|
readonly value: Value;
|
|
32
33
|
};
|
|
33
34
|
/** One loop iteration. Must be re-entrant: the same step object runs every round. */
|
|
34
|
-
export type CoreStep<Result> = (roundIndex: number, context: ExecutionContext & import('../debug.js').NodeReportingContext) => MaybePromise<StepOutcome<Result>>;
|
|
35
|
+
export type CoreStep<Result> = (roundIndex: number, context: ExecutionContext & import('../debug.js').NodeReportingContext & CacheContext) => MaybePromise<StepOutcome<Result>>;
|
|
35
36
|
/** Engine construction options. */
|
|
36
37
|
export interface AgentCoreEngineOptions {
|
|
38
|
+
/** Engine-local LRU bounds; not copied as cache data when forking. */
|
|
39
|
+
cache?: EngineCacheOptions;
|
|
40
|
+
/** Borrowed App service cache; forks must explicitly provide their own port. */
|
|
41
|
+
agentCache?: AgentCachePort;
|
|
37
42
|
/** Round budget; must be a positive safe integer. Defaults to 8 rounds. */
|
|
38
43
|
maxRounds?: number;
|
|
39
44
|
/** Cancellation and diagnostics shared by every round. */
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* `AgentWorkflowDefinition`, `WorkflowEvent`, `WorkflowFailure`, `WorkflowExtension`,
|
|
11
11
|
* `WorkflowModel`.
|
|
12
12
|
*/
|
|
13
|
+
import type { CacheContext } from './cache.js';
|
|
13
14
|
import type { OperationContext } from '../common.js';
|
|
14
15
|
import type { DiagnosticContext } from '../diagnostics.js';
|
|
15
16
|
import type { ModelTransportDefinition } from '../model/runtime.js';
|
|
@@ -20,7 +21,7 @@ type WorkflowModelRequest<Transport> = import('../model/runtime.js').ModelCallRe
|
|
|
20
21
|
readonly modelId?: string;
|
|
21
22
|
};
|
|
22
23
|
/** Execution facts available to every node of a running workflow. */
|
|
23
|
-
export interface WorkflowContext<Runtime = undefined> extends OperationContext<Runtime>, NodeReportingContext {
|
|
24
|
+
export interface WorkflowContext<Runtime = undefined> extends OperationContext<Runtime>, NodeReportingContext, CacheContext {
|
|
24
25
|
/** Zero-based bounded round; phases within a round do not consume another round. */
|
|
25
26
|
readonly roundIndex: number;
|
|
26
27
|
/** Report progress while this node is active; Core supplies its execution identity. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jangts/agent-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"description": "Platform-independent agent runtime and configurable modules for evidence, delivery, policies and interactions",
|
|
@@ -250,7 +250,7 @@
|
|
|
250
250
|
},
|
|
251
251
|
"dependencies": {
|
|
252
252
|
"@jangts/streaming": "^0.1.2",
|
|
253
|
-
"@jangts/mock-gpt": "0.2.
|
|
253
|
+
"@jangts/mock-gpt": "0.2.2",
|
|
254
254
|
"minisearch": "^7.2.0"
|
|
255
255
|
},
|
|
256
256
|
"devDependencies": {
|