RetrievalEffect
KIT · interface · Type contract
One effect applied after a successful query, in declaration order.
Import
ts
import type { RetrievalEffect } from '@jangts/agent-core/kits/retrieval';js
/** @typedef {import('@jangts/agent-core/kits/retrieval').RetrievalEffect} RetrievalEffect */Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/kits/retrieval, @jangts/agent-core/kits.
Definition
ts
interface RetrievalEffect<Query, Source, Result, Context>Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Query | — | — |
Source | RetrievalSource | — |
Result | RetrievalResult<Source> | — |
Context | — | — |
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Read-only. See the type definition and usage context. |
description | string | Required | Read-only. See the type definition and usage context. |
handle | (receipt: RetrievalReceipt<Query, Source, Result>, context: Context) => void | Required | Applies the effect synchronously; a throw stops later effects without rollback. |
Member index
| Member | Purpose |
|---|---|
handle | Applies the effect synchronously; a throw stops later effects without rollback. |
Member details
handle
Applies the effect synchronously; a throw stops later effects without rollback.
ts
RetrievalEffect.handle(receipt: RetrievalReceipt<Query, Source, Result>, context: Context): voidApplies the effect synchronously; a throw stops later effects without rollback.
| Parameter | Type | Passing | Description |
|---|---|---|---|
receipt | RetrievalReceipt<Query, Source, Result> | Required | — |
context | Context | Required | — |
Fields of receipt
| Field | Type | Required | Description |
|---|---|---|---|
query | Query | Required | Read-only. Query after prepare, exactly as executed. |
key | string | Required | Read-only. Deduplication key reserved before the adapter call. |
sequence | number | Required | Read-only. One-based position of this query within the request. |
startedAtMs | number | Required | Read-only. Adapter start instant in epoch milliseconds. |
rawResult | Result | Required | Read-only. Adapter output before source naming; rejected results never produce a receipt. |
result | Result | Required | Read-only. Same result with every sourceId replaced by the Kit-assigned name. |
extensions | Record<string, unknown> | Required | Read-only. Domain attachments are computed from real results, not model-supplied receipts. |
Returns: void.
Examples
- Retrieval: a synchronous retrieval lifecycle with quota: Keep normalization, validation, deduplication, authorization, reading, and follow-up effects on one deterministic call path.
Configure one read for the same product material
Beginner · Node.js
ts
import { Retrieval } from '@jangts/agent-core/kits/retrieval';
type Source = { sourceId: string; text: string };
const state = { queryCount: 0, seen: new Set<string>(), sources: [] as Source[] };
const documents = [{ sourceId: 'manual', text: 'Agent Core 使用指南' }];
const retrieval = Retrieval.defineRetrieval({
id: 'manual-search', description: '读取已确认的本地演示资料',
assertInput(query: string) { if (!query.trim()) throw new Error('查询为空'); },
state: () => state, limit: () => 2,
execute: (query: string) => ({ sources: documents.filter(item => item.text.includes(query)) }),
});
console.log(retrieval.run('Agent', { app: {}, signal: new AbortController().signal }).result);js
import { Retrieval } from '@jangts/agent-core/kits/retrieval';
const state = { queryCount: 0, seen: new Set(), sources: [] };
const documents = [{ sourceId: 'manual', text: 'Agent Core 使用指南' }];
const retrieval = Retrieval.defineRetrieval({
id: 'manual-search', description: '读取已确认的本地演示资料',
assertInput(query) { if (!query.trim())
throw new Error('查询为空'); },
state: () => state, limit: () => 2,
execute: (query) => ({ sources: documents.filter(item => item.text.includes(query)) }),
});
console.log(retrieval.run('Agent', { app: {}, signal: new AbortController().signal }).result);Add normalization, authorization, and receipt effects to the same run
Configuration · Node.js
ts
import { Retrieval } from '@jangts/agent-core/kits/retrieval';
type Source = { sourceId: string; text: string };
const state = { queryCount: 0, seen: new Set<string>(), sources: [] as Source[] };
const retrieval = Retrieval.defineRetrieval<string, Source, { sources: Source[] }, { canRead: boolean }>({
id: 'manual-search', description: '按当前服务端权限读取资料',
prepare: query => query.trim(),
assertInput(query) { if (!query) throw new Error('查询为空'); },
state: () => state, limit: () => 2,
authorize(_query, { app }) { if (!app.canRead) throw new Error('没有资料读取权限'); },
execute: query => ({ sources: [{ sourceId: 'manual', text: 'Agent Core 使用指南' }].filter(item => item.text.includes(query)) }),
effects: [{ id: 'source-count', description: '给真实回执附加来源数量', handle(receipt) { receipt.extensions.sourceCount = receipt.result.sources.length; } }],
});
const receipt = retrieval.run(' Agent ', { app: { canRead: true }, signal: new AbortController().signal });
console.log(receipt.sequence, receipt.extensions);js
import { Retrieval } from '@jangts/agent-core/kits/retrieval';
const state = { queryCount: 0, seen: new Set(), sources: [] };
const retrieval = Retrieval.defineRetrieval({
id: 'manual-search', description: '按当前服务端权限读取资料',
prepare: query => query.trim(),
assertInput(query) { if (!query)
throw new Error('查询为空'); },
state: () => state, limit: () => 2,
authorize(_query, { app }) { if (!app.canRead)
throw new Error('没有资料读取权限'); },
execute: query => ({ sources: [{ sourceId: 'manual', text: 'Agent Core 使用指南' }].filter(item => item.text.includes(query)) }),
effects: [{ id: 'source-count', description: '给真实回执附加来源数量', handle(receipt) { receipt.extensions.sourceCount = receipt.result.sources.length; } }],
});
const receipt = retrieval.run(' Agent ', { app: { canRead: true }, signal: new AbortController().signal });
console.log(receipt.sequence, receipt.extensions);