@theokit/agents 16.0.0 → 16.1.1
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 +32 -0
- package/README.md +47 -1
- package/dist/{agent-compiler-BMpuJFAI.d.ts → agent-compiler-JSYkHpa7.d.ts} +2 -2
- package/dist/{delegation-scoring-CURe4oSL.d.ts → agent-orchestrator-BFWg2URC.d.ts} +11 -426
- package/dist/agent-runner-BUJKNNuI.d.ts +364 -0
- package/dist/agent-sse-handler-BRp9vHrb.d.ts +348 -0
- package/dist/{bridge-entry-BxJWDpQP.d.ts → bridge-entry-BNWDrPzg.d.ts} +8 -422
- package/dist/bridge.d.ts +8 -5
- package/dist/bridge.js +19 -15
- package/dist/{chunk-4PHZ25JN.js → chunk-A7RXWJZE.js} +62 -1137
- package/dist/chunk-A7RXWJZE.js.map +1 -0
- package/dist/{chunk-FIGLHWR2.js → chunk-CJMYZKUL.js} +7 -7
- package/dist/chunk-MB23MSOK.js +353 -0
- package/dist/chunk-MB23MSOK.js.map +1 -0
- package/dist/chunk-SAKSZKVK.js +799 -0
- package/dist/chunk-SAKSZKVK.js.map +1 -0
- package/dist/delegation-scoring-Cn5eM4lQ.d.ts +79 -0
- package/dist/evals.d.ts +84 -0
- package/dist/evals.js +191 -0
- package/dist/evals.js.map +1 -0
- package/dist/handoff.d.ts +91 -0
- package/dist/handoff.js +268 -0
- package/dist/handoff.js.map +1 -0
- package/dist/index.d.ts +19 -369
- package/dist/index.js +36 -32
- package/dist/index.js.map +1 -1
- package/dist/mcp-health.d.ts +1 -1
- package/dist/sdk-adapter-DQnKx7bA.d.ts +435 -0
- package/dist/testing.d.ts +2 -2
- package/dist/tools.d.ts +5 -3
- package/dist/tools.js +10 -6
- package/dist/tools.js.map +1 -1
- package/dist/{types-DdltPCj2.d.ts → types-D5cHmSLi.d.ts} +1 -1
- package/docs/capability-map.md +31 -1
- package/package.json +12 -2
- package/dist/chunk-4PHZ25JN.js.map +0 -1
- /package/dist/{chunk-FIGLHWR2.js.map → chunk-CJMYZKUL.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/loop/compaction-strategy.ts","../src/loop/loop-strategy.ts","../src/loop/reflection-strategy.ts","../src/bridge/delegation-types.ts","../src/guardrails/terminal-frame.ts","../src/loop/run-budget.ts","../src/loop/round-usage.ts","../src/loop/run-reflective-loop.ts","../src/loop/agent-runner.ts"],"mappings":";;;;;;;;;;;;;;;AAcA,SAASA,yBAAmD;AAC5D,SAASC,SAAS;AAKX,IAAMC,sBAAsB;AAsD5B,IAAMC,iCAAiCC,EAAEC,OAAO;EACrDC,MAAMF,EAAEG,QAAQ,cAAA;EAChBC,YAAYJ,EAAEK,OAAM,EAAGC,IAAG,EAAGC,SAAQ;AACvC,CAAA;AAUO,SAASC,0BACdN,MACAO,QAA+B;AAE/B,QAAMC,MAAMX,+BAA+BY,MAAM;IAAET;IAAME,YAAYK,OAAOL;EAAW,CAAA;AACvF,SAAO;IACLF,MAAMQ,IAAIR;IACVE,YAAYM,IAAIN;IAChBQ,SAAS,wBAACC,UAAUC,YAClBC,kBAAkBF,UAAU;MAC1BT,YAAYU,SAASV,cAAcM,IAAIN;MACvCY,WAAWF,SAASE;MACpBC,QAAQH,SAASG;MACjBC,iBAAiBJ,SAASI;;MAE1BC,UAAUL,SAASK,YAAY;IACjC,CAAA,GARO;EASX;AACF;AAlBgBX;AAyBT,IAAMY,gCACXZ,0BAA0B,gBAAgB;EAAEJ,YAAYN;AAAoB,CAAA;;;ACtG9E,SAASuB,KAAAA,UAAS;AAyCX,IAAMC,yBAAyB;AAGtC,IAAMC,sBAAsBC,GAAEC,OAAM,EAAGC,IAAG,EAAGC,IAAI,CAAA;AAG1C,IAAMC,2BAA2BJ,GAAEK,OAAO;EAC/CC,MAAMN,GAAEO,KAAK;IAAC;IAAe;IAAoB;GAAQ;EACzDC,eAAeT;AACjB,CAAA;AAWO,SAASU,8BAA8BC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,GAAS;AACpE,SAAKN,qBAAqB;MAAER;MAAMe,YAAYD,QAAQC;IAAW;AACjE,WAAO;EACT;;EAGAC,QAAqB;AACnB,UAAM,EAAE3E,KAAI,IAAK;AAEjB,UAAMqE,WAAWrE,KAAKqE,YAAY;AAIlC,UAAM3E,uBAAuB,KAAK0E,yBAAyBQ;AAC3D,UAAMnF,eACJ,KAAK2E,wBAAwBV,oBAAoBW,UAAUrE,KAAK8B,aAAa;AAC/E,UAAMnC,qBACJ,KAAKuE,uBACJG,aAAa,qBAAqBQ,2BAA2BC;AAGhE,UAAMC,iBAAiB,KAAKZ,sBAAsBnE,KAAKH;AACvD,UAAMA,aAAakF,iBACfC,0BAA0BD,eAAepB,MAAM;MAAEe,YAAYK,eAAeL;IAAW,CAAA,IACvFE;AACJ,WAAO,IAAItF,YAAY;MACrBC,UAAUS,KAAKT;MACfC,WAAWQ,KAAK2D;MAChBlE;MACAC;MACAC;MACAC,eAAe,KAAKA;MACpBC;IACF,CAAA;EACF;AACF;","names":["compactTranscript","z","DEFAULT_KEEP_TOKENS","compactionStrategyConfigSchema","z","object","name","literal","keepTokens","number","int","positive","resolveCompactionStrategy","config","cfg","parse","compact","messages","options","compactTranscript","summarize","marker","summaryTemplate","failSafe","tokenBudgetCompactionStrategy","z","DEFAULT_MAX_ITERATIONS","maxIterationsSchema","z","number","int","min","loopStrategyConfigSchema","object","name","enum","maxIterations","assertValidCustomLoopStrategy","strategy","result","safeParse","success","Error","String","resolveLoopStrategy","cfg","parse","shouldContinue","outcome","round","finishReason","z","reflectionStrategyConfigSchema","object","name","string","min","ladderReflectionStrategy","reflect","outcome","finishReason","feedback","round","continue","noopReflectionStrategy","TheokitAgentError","budgetMessage","agentName","actualCost","budgetLimit","refusal","limit","toFixed","undefined","projectedRoundCost","DelegationBudgetExceededError","TheokitAgentError","name","code","isRetryable","DelegationBudgetCostUnknownError","knownSpend","costUnknown","BudgetExceededError","DelegationError","cause","Error","message","String","mirrorModeratedText","inner","round","sawText","step","next","done","event","value","type","content","result","refuseNextRound","spent","lastRound","ceiling","agentName","Number","isFinite","undefined","costKnown","DelegationBudgetCostUnknownError","cost","DelegationBudgetExceededError","projectedRoundCost","throwIfNextRoundRefused","signal","aborted","refusal","resolveRunBudget","budget","name","field","window","DelegationError","Error","maxCostUsd","isNaN","String","nothingToSpend","TOKEN_BUCKETS","DONE_USAGE_FIELDS","applyDone","event","r","costKnown","cost","Number","isFinite","usage","field","key","accumulateUsage","acc","costUnknown","tokens","bucket","asString","value","fallback","NO_PROGRESS_THRESHOLD","MAINLOOP_METRIC","TOOL_CALLS","STEP_LIMIT_HINT","stableStringify","undefined","JSON","stringify","Array","isArray","map","join","obj","entries","Object","keys","sort","a","b","localeCompare","k","roundSignature","toolCalls","tc","name","input","terminalReason","reflectionContinue","roundReason","round","maxIterations","CONTINUE_PROMPT","buildPrompt","message","feedback","hint","continuation","body","consumeRoundOrThrow","inputs","agentName","consumeOneRound","factory","prompt","sessionId","signal","retry","err","DelegationBudgetExceededError","DelegationError","GuardrailError","finalize","acc","reason","strategyName","rounds","finishReason","debugLog","strategy","terminal","deriveFinishReason","signals","sawError","sawDone","doneFinishReason","sawToolResult","pushToolResult","event","r","callInputs","id","callId","call","get","push","toolName","output","accumulateEvent","type","content","responseText","set","applyDone","errorMessage","startRound","open","it","Symbol","asyncIterator","first","next","return","Retry","run","cost","costKnown","tokens","tokensInput","tokensOutput","reasoningTokens","cacheReadTokens","cacheWriteTokens","Map","done","aborted","ceilingRoundFactory","m","s","disableTools","runReflectiveLoopStream","config","loop","reflection","budget","Number","POSITIVE_INFINITY","response","reflectionContext","prevSig","stuck","roundFactory","accumulateUsage","isFinite","length","sig","outcome","reflectionResult","reflect","continue","shouldContinue","throwIfNextRoundRefused","runReflectiveLoop","gen","res","AgentRunner","compiled","agentName","loopStrategy","loopStrategyIsCustom","reflectionStrategy","streamEnabled","compaction","state","fromSpec","spec","AgentRunnerBuilder","stream","message","opts","runOpts","budget","resolveRunBudget","guardrails","length","runUnguarded","m","streamUnguarded","guarded","safe","runInputGuards","mirrorModeratedText","moderateOutputStream","textPayloadExtractor","e","content","type","result","response","_content","text","_text","tools","loop","resolvePerRunLoop","maxIterations","streamFactory","createSdkAgentStream","apiKey","model","reasoningEffort","parseThinkTags","stripToolDialect","recoverLeakedToolCalls","cwd","baseDir","plugins","providers","agents","budgetTracker","sdkTools","sessionId","crypto","randomUUID","runReflectiveLoopStream","reflection","signal","retry","base","Object","assign","create","getPrototypeOf","resolveLoopStrategy","name","run","gen","res","next","done","value","reflectionOverride","compactionOverride","loopStrategyOverride","strategy","custom","assertValidCustomLoopStrategy","enabled","options","keepTokens","build","undefined","ladderReflectionStrategy","noopReflectionStrategy","compactionDecl","resolveCompactionStrategy"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { D as DelegationResult, S as SubAgentSpec, a as DelegateOptions } from './agent-orchestrator-BFWg2URC.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* M25 (theokit-ai-first) — background delegation + task-completion scoring.
|
|
5
|
+
*
|
|
6
|
+
* Two THIN wrappers over the M12 `delegate` (ADR 0038/0040): no new orchestration engine, no second
|
|
7
|
+
* loop, no new store. `delegateBackground` kicks off a sub-agent without blocking the supervisor and
|
|
8
|
+
* hands back a handle to await later. `delegateWithScoring` runs `delegate`, scores the result with
|
|
9
|
+
* an injected scorer, and re-delegates with the scorer's feedback until it passes or `maxRounds` is
|
|
10
|
+
* hit. The `delegate` implementation is injectable (`delegateFn`) so this is testable without a
|
|
11
|
+
* SubAgent class or an LLM — and so it NEVER re-implements the delegation runtime.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* M81 — anything that can run a delegation.
|
|
16
|
+
*
|
|
17
|
+
* The reach gap this closes: both wrappers took a `SubAgentSpec` produced by the capability
|
|
18
|
+
* compiler, so a consumer holding an SDK `SubAgent` or `Squad` could not feed them. That is why the
|
|
19
|
+
* scoring loop — the layer's highest-value piece — had ZERO adoption in a product that runs an
|
|
20
|
+
* explicit review pass: it was unreachable from the primitives that product actually holds.
|
|
21
|
+
*
|
|
22
|
+
* An SDK `SubAgent` or `Squad` satisfies this by having `run`. So does a test double, which is why
|
|
23
|
+
* the loop is now testable without a compiler, a class or an LLM.
|
|
24
|
+
*/
|
|
25
|
+
interface DelegationPort {
|
|
26
|
+
run(message: string): Promise<DelegationResult>;
|
|
27
|
+
}
|
|
28
|
+
/** What both wrappers accept: the compiled spec (unchanged) or the port (M81, additive). */
|
|
29
|
+
type DelegationTarget = SubAgentSpec | DelegationPort;
|
|
30
|
+
/** The delegation primitive both wrappers drive. Defaults to the M12 {@link delegate}. */
|
|
31
|
+
type DelegateFn = (subAgent: SubAgentSpec, message: string, opts?: DelegateOptions) => Promise<DelegationResult>;
|
|
32
|
+
/** A running background delegation the supervisor can await/poll later. */
|
|
33
|
+
interface BackgroundDelegation {
|
|
34
|
+
/** Await the sub-agent's result (or rejection). Idempotent — returns the same settled promise. */
|
|
35
|
+
wait(): Promise<DelegationResult>;
|
|
36
|
+
/** Whether the underlying delegation has resolved or rejected. */
|
|
37
|
+
settled(): boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Start a sub-agent WITHOUT blocking the supervisor. Returns immediately with a handle; the
|
|
41
|
+
* supervisor keeps working and calls `wait()` when it needs the result. A thin async wrapper over
|
|
42
|
+
* `delegate` — not a scheduler (Top-risk 1). Rejections are still observable via `wait()`.
|
|
43
|
+
*/
|
|
44
|
+
declare function delegateBackground(subAgent: DelegationTarget, message: string, opts?: DelegateOptions & {
|
|
45
|
+
delegateFn?: DelegateFn;
|
|
46
|
+
}): BackgroundDelegation;
|
|
47
|
+
/** A scorer's verdict on a sub-agent result. `feedback` is fed back into the next round on failure. */
|
|
48
|
+
interface ScoreVerdict {
|
|
49
|
+
pass: boolean;
|
|
50
|
+
/** Optional numeric score (0..1) for logging/telemetry. */
|
|
51
|
+
score?: number;
|
|
52
|
+
/** Guidance appended to the next delegation when `pass` is false. */
|
|
53
|
+
feedback?: string;
|
|
54
|
+
}
|
|
55
|
+
/** Scores a sub-agent result. Opt-in (Top-risk 2) — the caller supplies it, and pays its cost. */
|
|
56
|
+
type Scorer = (result: DelegationResult) => ScoreVerdict | Promise<ScoreVerdict>;
|
|
57
|
+
/** The outcome of a scored delegation: the final result plus the per-round verdict trail. */
|
|
58
|
+
interface ScoredDelegation {
|
|
59
|
+
result: DelegationResult;
|
|
60
|
+
/** Rounds actually run (1..maxRounds). */
|
|
61
|
+
rounds: number;
|
|
62
|
+
/** Whether the final round passed the scorer. */
|
|
63
|
+
passed: boolean;
|
|
64
|
+
/** The verdict from each round, in order. */
|
|
65
|
+
verdicts: ScoreVerdict[];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Run `delegate`, score the result, and re-delegate with the scorer's feedback until it passes or
|
|
69
|
+
* `maxRounds` is reached. Each round is ONE `delegate` call — no second loop, no new store. Returns
|
|
70
|
+
* the final result (passing, or the last attempt) with the per-round verdict trail.
|
|
71
|
+
*/
|
|
72
|
+
declare function delegateWithScoring(subAgent: DelegationTarget, message: string, opts: DelegateOptions & {
|
|
73
|
+
scorer: Scorer;
|
|
74
|
+
maxRounds?: number;
|
|
75
|
+
delegateFn?: DelegateFn;
|
|
76
|
+
feedbackTemplate?: (message: string, feedback: string) => string;
|
|
77
|
+
}): Promise<ScoredDelegation>;
|
|
78
|
+
|
|
79
|
+
export { type BackgroundDelegation as B, type DelegationTarget as D, type ScoreVerdict as S, type DelegateFn as a, type DelegationPort as b, type ScoredDelegation as c, type Scorer as d, delegateBackground as e, delegateWithScoring as f };
|
package/dist/evals.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { TheokitAgentError } from '@theokit/sdk/errors';
|
|
2
|
+
import { Scorer, NamedScorer } from '@theokit/sdk/eval';
|
|
3
|
+
export { EvalAlreadyRunningError, NamedScorer, Scorer, Scorers } from '@theokit/sdk/eval';
|
|
4
|
+
import { D as DefinitionOrThunk, A as ApprovalPosture, R as RuntimeOverrides } from './sdk-adapter-DQnKx7bA.js';
|
|
5
|
+
import '@theokit/sdk';
|
|
6
|
+
import '@theokit/sdk/retry';
|
|
7
|
+
import './types-D5cHmSLi.js';
|
|
8
|
+
import 'zod';
|
|
9
|
+
import './agent-compiler-JSYkHpa7.js';
|
|
10
|
+
import '@theokit/sdk/subagents-loader';
|
|
11
|
+
import './setting-sources-gate-BJJiKq33.js';
|
|
12
|
+
import './hook-handlers-Cw2FsnE5.js';
|
|
13
|
+
import './agent-sse-handler-BRp9vHrb.js';
|
|
14
|
+
import '@theokit/presenter/wire';
|
|
15
|
+
import '@theokit/sdk/sandbox';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* B-413 — run a list of cases against a theokit agent definition and read a verdict per case.
|
|
19
|
+
*
|
|
20
|
+
* This is a layer over the SDK's `Eval` runner, not a second runner (ADR D1): the SDK runs each case,
|
|
21
|
+
* scores it and isolates its failure; this module builds each case's agent through
|
|
22
|
+
* {@link toAgentFactory}, disposes what it built, and maps every returned row to `pass`, `fail` or
|
|
23
|
+
* `error`.
|
|
24
|
+
*
|
|
25
|
+
* `error` means nobody measured the answer: the run did not finish, a guard stopped the turn, the
|
|
26
|
+
* factory threw, or a scorer threw or returned something that is not a score within [0, 1] (ADR D2).
|
|
27
|
+
* Such a case is never counted as `fail`, which would tell the caller the agent answered badly.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/** One input the caller wants checked; the SDK calls it a dataset entry. */
|
|
31
|
+
interface AgentEvalCase {
|
|
32
|
+
input: string;
|
|
33
|
+
expected?: unknown;
|
|
34
|
+
}
|
|
35
|
+
/** This layer's answer for one case. */
|
|
36
|
+
type AgentEvalVerdict = 'pass' | 'fail' | 'error';
|
|
37
|
+
interface AgentEvalCaseResult {
|
|
38
|
+
index: number;
|
|
39
|
+
input: string;
|
|
40
|
+
expected?: unknown;
|
|
41
|
+
output: string;
|
|
42
|
+
verdict: AgentEvalVerdict;
|
|
43
|
+
meanScore: number;
|
|
44
|
+
scores: readonly {
|
|
45
|
+
readonly name: string;
|
|
46
|
+
readonly score: number;
|
|
47
|
+
readonly reason?: string;
|
|
48
|
+
}[];
|
|
49
|
+
/** Why the case is an `error`; absent on `pass` and `fail`. */
|
|
50
|
+
error?: string;
|
|
51
|
+
durationMs: number;
|
|
52
|
+
}
|
|
53
|
+
interface AgentEvalResult {
|
|
54
|
+
name: string;
|
|
55
|
+
threshold: number;
|
|
56
|
+
cases: AgentEvalCaseResult[];
|
|
57
|
+
counts: {
|
|
58
|
+
pass: number;
|
|
59
|
+
fail: number;
|
|
60
|
+
error: number;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
interface RunAgentEvalsOptions {
|
|
64
|
+
/** The definition under test, or a per-session thunk that returns one. */
|
|
65
|
+
agent: DefinitionOrThunk;
|
|
66
|
+
apiKey: string | (() => string | Promise<string>);
|
|
67
|
+
/** Mandatory, as on {@link toAgentFactory}: what a gated tool's approval request gets (ADR D3). */
|
|
68
|
+
approvals: ApprovalPosture;
|
|
69
|
+
cases: readonly AgentEvalCase[];
|
|
70
|
+
scorers: readonly (Scorer | NamedScorer)[];
|
|
71
|
+
/** A case passes when its mean score is at or above this. Within [0, 1]; default 0.5. */
|
|
72
|
+
threshold?: number;
|
|
73
|
+
/** The SDK run's name. Default `theokit-agent-evals-<uuid>`, so unnamed runs never collide (ADR D4). */
|
|
74
|
+
name?: string;
|
|
75
|
+
overrides?: RuntimeOverrides;
|
|
76
|
+
}
|
|
77
|
+
/** A configuration `runAgentEvals` refuses before it builds any agent. */
|
|
78
|
+
declare class EvalConfigError extends TheokitAgentError {
|
|
79
|
+
readonly name = "EvalConfigError";
|
|
80
|
+
constructor(message: string);
|
|
81
|
+
}
|
|
82
|
+
declare function runAgentEvals(opts: RunAgentEvalsOptions): Promise<AgentEvalResult>;
|
|
83
|
+
|
|
84
|
+
export { type AgentEvalCase, type AgentEvalCaseResult, type AgentEvalResult, type AgentEvalVerdict, EvalConfigError, type RunAgentEvalsOptions, runAgentEvals };
|
package/dist/evals.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import {
|
|
2
|
+
toAgentFactory
|
|
3
|
+
} from "./chunk-A7RXWJZE.js";
|
|
4
|
+
import "./chunk-M5J3Q6YC.js";
|
|
5
|
+
import "./chunk-Q65ZIFNK.js";
|
|
6
|
+
import "./chunk-NIQJ4GZX.js";
|
|
7
|
+
import "./chunk-2SP5BB6U.js";
|
|
8
|
+
import "./chunk-OXNDJSAJ.js";
|
|
9
|
+
import {
|
|
10
|
+
__name
|
|
11
|
+
} from "./chunk-Z4QWC7IK.js";
|
|
12
|
+
|
|
13
|
+
// src/evals/run-agent-evals.ts
|
|
14
|
+
import { TheokitAgentError } from "@theokit/sdk/errors";
|
|
15
|
+
import { Eval } from "@theokit/sdk/eval";
|
|
16
|
+
var EvalConfigError = class extends TheokitAgentError {
|
|
17
|
+
static {
|
|
18
|
+
__name(this, "EvalConfigError");
|
|
19
|
+
}
|
|
20
|
+
name = "EvalConfigError";
|
|
21
|
+
constructor(message) {
|
|
22
|
+
super(`[@theokit/agents] ${message}`, {
|
|
23
|
+
code: "eval_config_invalid",
|
|
24
|
+
isRetryable: false
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var DEFAULT_THRESHOLD = 0.5;
|
|
29
|
+
async function runAgentEvals(opts) {
|
|
30
|
+
validate(opts);
|
|
31
|
+
const name = opts.name ?? `theokit-agent-evals-${crypto.randomUUID()}`;
|
|
32
|
+
const threshold = opts.threshold ?? DEFAULT_THRESHOLD;
|
|
33
|
+
const factory = toAgentFactory(opts.agent, {
|
|
34
|
+
apiKey: opts.apiKey,
|
|
35
|
+
approvals: opts.approvals,
|
|
36
|
+
...opts.overrides === void 0 ? {} : {
|
|
37
|
+
overrides: opts.overrides
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const runId = crypto.randomUUID();
|
|
41
|
+
const handles = [];
|
|
42
|
+
let caseNumber = 0;
|
|
43
|
+
const agentFor = /* @__PURE__ */ __name(async () => {
|
|
44
|
+
caseNumber += 1;
|
|
45
|
+
const handle = await factory(`${name}-${runId}-case-${String(caseNumber)}`);
|
|
46
|
+
handles.push(handle);
|
|
47
|
+
return handle;
|
|
48
|
+
}, "agentFor");
|
|
49
|
+
const failureMark = `theokit-scorer-failed-${runId}: `;
|
|
50
|
+
const scorers = opts.scorers.map((scorer, index) => strictScorer(scorer, index, failureMark));
|
|
51
|
+
let rows;
|
|
52
|
+
try {
|
|
53
|
+
const run = await Eval.create({
|
|
54
|
+
name,
|
|
55
|
+
dataset: opts.cases,
|
|
56
|
+
scorers,
|
|
57
|
+
agent: asEvalAgentFactory(agentFor)
|
|
58
|
+
}).run();
|
|
59
|
+
rows = run.rows;
|
|
60
|
+
} catch (runError) {
|
|
61
|
+
await Promise.allSettled(handles.map((h) => h.dispose()));
|
|
62
|
+
throw runError;
|
|
63
|
+
}
|
|
64
|
+
await Promise.all(handles.map((h) => h.dispose()));
|
|
65
|
+
const cases = rows.map((row) => toCaseResult(row, threshold, failureMark));
|
|
66
|
+
return {
|
|
67
|
+
name,
|
|
68
|
+
threshold,
|
|
69
|
+
cases,
|
|
70
|
+
counts: countVerdicts(cases)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
__name(runAgentEvals, "runAgentEvals");
|
|
74
|
+
function validate(opts) {
|
|
75
|
+
if (!Array.isArray(opts.cases) || opts.cases.length === 0) {
|
|
76
|
+
throw new EvalConfigError("runAgentEvals: cases must be a non-empty array");
|
|
77
|
+
}
|
|
78
|
+
opts.cases.forEach((c, i) => {
|
|
79
|
+
const entry = c;
|
|
80
|
+
const input = typeof entry === "object" && entry !== null ? entry.input : void 0;
|
|
81
|
+
if (typeof input !== "string") {
|
|
82
|
+
throw new EvalConfigError(`runAgentEvals: cases[${String(i)}].input must be a string, got ${typeof input}`);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
if (!Array.isArray(opts.scorers) || opts.scorers.length === 0) {
|
|
86
|
+
throw new EvalConfigError("runAgentEvals: scorers must be a non-empty array");
|
|
87
|
+
}
|
|
88
|
+
const t = opts.threshold;
|
|
89
|
+
if (t !== void 0 && !(Number.isFinite(t) && t >= 0 && t <= 1)) {
|
|
90
|
+
throw new EvalConfigError(`runAgentEvals: threshold must be within [0, 1], got ${String(t)}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
__name(validate, "validate");
|
|
94
|
+
function strictScorer(scorer, index, failureMark) {
|
|
95
|
+
const name = typeof scorer === "function" ? `scorer-${String(index)}` : scorer.name;
|
|
96
|
+
const score = typeof scorer === "function" ? scorer : scorer.score;
|
|
97
|
+
const failed = /* @__PURE__ */ __name((why) => ({
|
|
98
|
+
score: 0,
|
|
99
|
+
reason: `${failureMark}scorer ${name} ${why}`
|
|
100
|
+
}), "failed");
|
|
101
|
+
return {
|
|
102
|
+
name,
|
|
103
|
+
score: /* @__PURE__ */ __name(async (output, expected) => {
|
|
104
|
+
let result;
|
|
105
|
+
try {
|
|
106
|
+
result = await score(output, expected);
|
|
107
|
+
} catch (scorerError) {
|
|
108
|
+
return failed(`threw: ${scorerError instanceof Error ? scorerError.message : describe(scorerError)}`);
|
|
109
|
+
}
|
|
110
|
+
if (!isUnitScore(result)) {
|
|
111
|
+
return failed(`returned ${describeScore(result)}, not { score: number within [0, 1], reason?: string }`);
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}, "score")
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
__name(strictScorer, "strictScorer");
|
|
118
|
+
function isUnitScore(value) {
|
|
119
|
+
if (typeof value !== "object" || value === null) return false;
|
|
120
|
+
const { score, reason } = value;
|
|
121
|
+
return typeof score === "number" && score >= 0 && score <= 1 && (reason === void 0 || typeof reason === "string");
|
|
122
|
+
}
|
|
123
|
+
__name(isUnitScore, "isUnitScore");
|
|
124
|
+
function describeScore(value) {
|
|
125
|
+
if (typeof value === "object" && value !== null && "score" in value) {
|
|
126
|
+
return describe(value.score);
|
|
127
|
+
}
|
|
128
|
+
return describe(value);
|
|
129
|
+
}
|
|
130
|
+
__name(describeScore, "describeScore");
|
|
131
|
+
function describe(value) {
|
|
132
|
+
try {
|
|
133
|
+
return String(value);
|
|
134
|
+
} catch {
|
|
135
|
+
return `a value of type ${typeof value} with no string form`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
__name(describe, "describe");
|
|
139
|
+
function asEvalAgentFactory(agentFor) {
|
|
140
|
+
return agentFor;
|
|
141
|
+
}
|
|
142
|
+
__name(asEvalAgentFactory, "asEvalAgentFactory");
|
|
143
|
+
function toCaseResult(row, threshold, failureMark) {
|
|
144
|
+
const scores = row.scores.map((s) => s.reason?.startsWith(failureMark) === true ? {
|
|
145
|
+
...s,
|
|
146
|
+
reason: s.reason.slice(failureMark.length)
|
|
147
|
+
} : s);
|
|
148
|
+
const failure = row.scores.find((s) => s.reason?.startsWith(failureMark) === true);
|
|
149
|
+
const error = row.error ?? failure?.reason?.slice(failureMark.length);
|
|
150
|
+
return {
|
|
151
|
+
index: row.index,
|
|
152
|
+
input: row.input,
|
|
153
|
+
...row.expected === void 0 ? {} : {
|
|
154
|
+
expected: row.expected
|
|
155
|
+
},
|
|
156
|
+
output: row.output,
|
|
157
|
+
verdict: verdictOf(error, row.meanScore, threshold),
|
|
158
|
+
meanScore: row.meanScore,
|
|
159
|
+
scores,
|
|
160
|
+
...error === void 0 ? {} : {
|
|
161
|
+
error
|
|
162
|
+
},
|
|
163
|
+
durationMs: row.durationMs
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
__name(toCaseResult, "toCaseResult");
|
|
167
|
+
function verdictOf(error, meanScore, threshold) {
|
|
168
|
+
if (error !== void 0) return "error";
|
|
169
|
+
return meanScore >= threshold ? "pass" : "fail";
|
|
170
|
+
}
|
|
171
|
+
__name(verdictOf, "verdictOf");
|
|
172
|
+
function countVerdicts(cases) {
|
|
173
|
+
const counts = {
|
|
174
|
+
pass: 0,
|
|
175
|
+
fail: 0,
|
|
176
|
+
error: 0
|
|
177
|
+
};
|
|
178
|
+
for (const c of cases) counts[c.verdict] += 1;
|
|
179
|
+
return counts;
|
|
180
|
+
}
|
|
181
|
+
__name(countVerdicts, "countVerdicts");
|
|
182
|
+
|
|
183
|
+
// src/evals-entry.ts
|
|
184
|
+
import { EvalAlreadyRunningError, Scorers } from "@theokit/sdk/eval";
|
|
185
|
+
export {
|
|
186
|
+
EvalAlreadyRunningError,
|
|
187
|
+
EvalConfigError,
|
|
188
|
+
Scorers,
|
|
189
|
+
runAgentEvals
|
|
190
|
+
};
|
|
191
|
+
//# sourceMappingURL=evals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/evals/run-agent-evals.ts","../src/evals-entry.ts"],"mappings":";;;;;;;;;;;;;AAaA,SAASA,yBAAyB;AAClC,SACEC,YAMK;AAuDA,IAAMC,kBAAN,cAA8BC,kBAAAA;EA5ErC,OA4EqCA;;;EACjBC,OAAO;EAEzB,YAAYC,SAAiB;AAE3B,UAAM,qBAAqBA,OAAAA,IAAW;MAAEC,MAAM;MAAuBC,aAAa;IAAM,CAAA;EAC1F;AACF;AAEA,IAAMC,oBAAoB;AAE1B,eAAsBC,cAAcC,MAA0B;AAC5DC,WAASD,IAAAA;AACT,QAAMN,OAAOM,KAAKN,QAAQ,uBAAuBQ,OAAOC,WAAU,CAAA;AAClE,QAAMC,YAAYJ,KAAKI,aAAaN;AACpC,QAAMO,UAAUC,eAAeN,KAAKO,OAAO;IACzCC,QAAQR,KAAKQ;IACbC,WAAWT,KAAKS;IAChB,GAAIT,KAAKU,cAAcC,SAAY,CAAC,IAAI;MAAED,WAAWV,KAAKU;IAAU;EACtE,CAAA;AAGA,QAAME,QAAQV,OAAOC,WAAU;AAC/B,QAAMU,UAA4B,CAAA;AAClC,MAAIC,aAAa;AACjB,QAAMC,WAAW,mCAAA;AAEfD,kBA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IoE,UAAU7D,OAAW,QAAO;AAChC,SAAOgE,aAAavE,YAAY,SAAS;AAC3C;AAPSsE;AAST,SAASjC,cAAcX,OAAqC;AAC1D,QAAMU,SAAS;IAAEqC,MAAM;IAAGC,MAAM;IAAGN,OAAO;EAAE;AAC5C,aAAW1B,KAAKhB,MAAOU,QAAOM,EAAE2B,OAAO,KAAK;AAC5C,SAAOjC;AACT;AAJSC;;;AC1PT,SAASsC,yBAAyBC,eAAe;","names":["TheokitAgentError","Eval","EvalConfigError","TheokitAgentError","name","message","code","isRetryable","DEFAULT_THRESHOLD","runAgentEvals","opts","validate","crypto","randomUUID","threshold","factory","toAgentFactory","agent","apiKey","approvals","overrides","undefined","runId","handles","caseNumber","agentFor","handle","String","push","failureMark","scorers","map","scorer","index","strictScorer","rows","run","Eval","create","dataset","cases","asEvalAgentFactory","runError","Promise","allSettled","h","dispose","all","row","toCaseResult","counts","countVerdicts","Array","isArray","length","forEach","c","i","entry","input","t","Number","isFinite","score","failed","why","reason","output","expected","result","scorerError","Error","describe","isUnitScore","describeScore","value","scores","s","startsWith","slice","failure","find","error","verdict","verdictOf","meanScore","durationMs","pass","fail","EvalAlreadyRunningError","Scorers"]}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { TheokitAgentError } from '@theokit/sdk/errors';
|
|
2
|
+
import { S as SubAgentSpec, D as DelegationResult } from './agent-orchestrator-BFWg2URC.js';
|
|
3
|
+
import { A as AgentRunnerRunOptions } from './agent-runner-BUJKNNuI.js';
|
|
4
|
+
import '@theokit/sdk';
|
|
5
|
+
import '@theokit/sdk/retry';
|
|
6
|
+
import './agent-compiler-JSYkHpa7.js';
|
|
7
|
+
import '@theokit/sdk/subagents-loader';
|
|
8
|
+
import './types-D5cHmSLi.js';
|
|
9
|
+
import 'zod';
|
|
10
|
+
import './setting-sources-gate-BJJiKq33.js';
|
|
11
|
+
import './hook-handlers-Cw2FsnE5.js';
|
|
12
|
+
import './agent-sse-handler-BRp9vHrb.js';
|
|
13
|
+
import '@theokit/presenter/wire';
|
|
14
|
+
import '@theokit/sdk/compaction';
|
|
15
|
+
|
|
16
|
+
type HandoffErrorCode = 'unknown_agent' | 'roster_too_small' | 'duplicate_name' | 'turn_in_progress' | 'step_ceiling_too_low' | 'reserved_tool_name' | 'invalid_agent_name' | 'already_responder';
|
|
17
|
+
/** A roster misconfiguration, an unknown target, or a call made while a turn is running. */
|
|
18
|
+
declare class HandoffError extends TheokitAgentError {
|
|
19
|
+
readonly code: HandoffErrorCode;
|
|
20
|
+
readonly name = "HandoffError";
|
|
21
|
+
constructor(message: string, code: HandoffErrorCode);
|
|
22
|
+
}
|
|
23
|
+
interface CreateHandoffConversationOptions {
|
|
24
|
+
/** The agents the conversation can hand off between: at least 2, each with a unique name. */
|
|
25
|
+
readonly agents: readonly SubAgentSpec[];
|
|
26
|
+
/** The name of the agent that answers the first message. */
|
|
27
|
+
readonly initial: string;
|
|
28
|
+
/**
|
|
29
|
+
* Prefix of each agent's session id (`<conversationId>:<agentName>`). Default: a fresh UUID. Only
|
|
30
|
+
* one conversation may run a turn on an id at a time; the responder and a waiting note live in
|
|
31
|
+
* this object's memory, not in the id.
|
|
32
|
+
*/
|
|
33
|
+
readonly conversationId?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The run options a turn accepts: every `AgentRunner.run` option except the four the conversation
|
|
37
|
+
* owns. The session id and the tool list are the conversation's; a `streamFactory` replaces the
|
|
38
|
+
* adapter and with it the transfer tool; a per-run `maxIterations` of 1 disables tools in round 1.
|
|
39
|
+
*/
|
|
40
|
+
type HandoffSendOptions = Omit<AgentRunnerRunOptions, 'sessionId' | 'tools' | 'streamFactory' | 'maxIterations'>;
|
|
41
|
+
/** A transfer committed by a turn. */
|
|
42
|
+
interface HandoffTransfer {
|
|
43
|
+
readonly from: string;
|
|
44
|
+
readonly to: string;
|
|
45
|
+
readonly note: string;
|
|
46
|
+
}
|
|
47
|
+
/** One turn's result: the run's result, the agent that answered it, and the transfer it made. */
|
|
48
|
+
interface HandoffTurn extends DelegationResult {
|
|
49
|
+
readonly responder: string;
|
|
50
|
+
readonly handoff?: HandoffTransfer;
|
|
51
|
+
}
|
|
52
|
+
interface HandoffConversation {
|
|
53
|
+
readonly conversationId: string;
|
|
54
|
+
/** The agent that answers the next message. */
|
|
55
|
+
readonly responder: string;
|
|
56
|
+
/**
|
|
57
|
+
* Run one turn on the current responder. Rejects with `turn_in_progress` while a turn runs on
|
|
58
|
+
* this conversation or on another one with the same `conversationId`, and with
|
|
59
|
+
* `reserved_tool_name` when `opts.sdkTools` names `transfer_to_agent`.
|
|
60
|
+
*/
|
|
61
|
+
send(message: string, opts: HandoffSendOptions): Promise<HandoffTurn>;
|
|
62
|
+
/**
|
|
63
|
+
* Move the next turn to `name`; `note` is put in front of that agent's next message. Naming the
|
|
64
|
+
* agent that already answers changes nothing; naming it with a `note` throws `already_responder`,
|
|
65
|
+
* because no transfer would carry the note.
|
|
66
|
+
*/
|
|
67
|
+
handoffTo(name: string, note?: string): void;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Create a conversation that one agent can hand to another.
|
|
71
|
+
*
|
|
72
|
+
* Each agent runs on its own session (`<conversationId>:<agentName>`) and is offered a
|
|
73
|
+
* `transfer_to_agent` tool naming the other agents. A transfer the agent requests is committed when
|
|
74
|
+
* its run returns normally and was not cancelled, so the NEXT `send()` is answered by the target,
|
|
75
|
+
* which reads the transferring agent's note before the user's message. The note is written by a
|
|
76
|
+
* model and the message by the user; neither can open the receiver's message with a note, because
|
|
77
|
+
* `[Handoff from` inside either, and its lookalikes (fullwidth or accented letters, zero-width
|
|
78
|
+
* characters, another bracket or separator), is rewritten to `[quoted: Handoff from`.
|
|
79
|
+
*
|
|
80
|
+
* The responder and a waiting note live in memory. To resume after a restart, keep the last
|
|
81
|
+
* `turn.handoff`. If the receiver has not answered yet, create the conversation with `initial` set
|
|
82
|
+
* to its `from` and call `handoffTo(handoff.to, handoff.note)`, which rebuilds the note with its
|
|
83
|
+
* sender; once the receiver has answered, create it with `initial` set to its `to`.
|
|
84
|
+
*
|
|
85
|
+
* @throws {HandoffError} `roster_too_small`, `duplicate_name`, `invalid_agent_name` (a ':' in a
|
|
86
|
+
* name), `step_ceiling_too_low`, `reserved_tool_name` or `unknown_agent` (for `initial`) at
|
|
87
|
+
* creation.
|
|
88
|
+
*/
|
|
89
|
+
declare function createHandoffConversation(options: CreateHandoffConversationOptions): HandoffConversation;
|
|
90
|
+
|
|
91
|
+
export { type CreateHandoffConversationOptions, type HandoffConversation, HandoffError, type HandoffErrorCode, type HandoffSendOptions, type HandoffTransfer, type HandoffTurn, SubAgentSpec, createHandoffConversation };
|