@spendgraph/workflows 0.2.0
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/README.md +149 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/noesis/attribution.d.ts +24 -0
- package/dist/noesis/attribution.js +43 -0
- package/dist/noesis/context.d.ts +18 -0
- package/dist/noesis/context.js +16 -0
- package/dist/noesis/draft/draft.d.ts +18 -0
- package/dist/noesis/draft/draft.js +50 -0
- package/dist/noesis/draft/index.d.ts +2 -0
- package/dist/noesis/draft/index.js +1 -0
- package/dist/noesis/draft/types.d.ts +27 -0
- package/dist/noesis/draft/types.js +1 -0
- package/dist/noesis/events.d.ts +158 -0
- package/dist/noesis/events.js +24 -0
- package/dist/noesis/execute/execute.d.ts +22 -0
- package/dist/noesis/execute/execute.js +85 -0
- package/dist/noesis/execute/index.d.ts +3 -0
- package/dist/noesis/execute/index.js +2 -0
- package/dist/noesis/execute/order.d.ts +11 -0
- package/dist/noesis/execute/order.js +28 -0
- package/dist/noesis/execute/types.d.ts +37 -0
- package/dist/noesis/execute/types.js +1 -0
- package/dist/noesis/gates/closure-checklist/index.d.ts +3 -0
- package/dist/noesis/gates/closure-checklist/index.js +2 -0
- package/dist/noesis/gates/closure-checklist/invoke.d.ts +5 -0
- package/dist/noesis/gates/closure-checklist/invoke.js +6 -0
- package/dist/noesis/gates/closure-checklist/prompt.d.ts +5 -0
- package/dist/noesis/gates/closure-checklist/prompt.js +32 -0
- package/dist/noesis/gates/closure-checklist/types.d.ts +20 -0
- package/dist/noesis/gates/closure-checklist/types.js +1 -0
- package/dist/noesis/gates/cqot-gate/index.d.ts +3 -0
- package/dist/noesis/gates/cqot-gate/index.js +2 -0
- package/dist/noesis/gates/cqot-gate/invoke.d.ts +5 -0
- package/dist/noesis/gates/cqot-gate/invoke.js +6 -0
- package/dist/noesis/gates/cqot-gate/prompt.d.ts +5 -0
- package/dist/noesis/gates/cqot-gate/prompt.js +27 -0
- package/dist/noesis/gates/cqot-gate/types.d.ts +23 -0
- package/dist/noesis/gates/cqot-gate/types.js +1 -0
- package/dist/noesis/gates/premortem/index.d.ts +3 -0
- package/dist/noesis/gates/premortem/index.js +2 -0
- package/dist/noesis/gates/premortem/invoke.d.ts +5 -0
- package/dist/noesis/gates/premortem/invoke.js +6 -0
- package/dist/noesis/gates/premortem/prompt.d.ts +5 -0
- package/dist/noesis/gates/premortem/prompt.js +37 -0
- package/dist/noesis/gates/premortem/types.d.ts +28 -0
- package/dist/noesis/gates/premortem/types.js +1 -0
- package/dist/noesis/gates/red-team/index.d.ts +3 -0
- package/dist/noesis/gates/red-team/index.js +2 -0
- package/dist/noesis/gates/red-team/invoke.d.ts +5 -0
- package/dist/noesis/gates/red-team/invoke.js +6 -0
- package/dist/noesis/gates/red-team/prompt.d.ts +5 -0
- package/dist/noesis/gates/red-team/prompt.js +25 -0
- package/dist/noesis/gates/red-team/types.d.ts +21 -0
- package/dist/noesis/gates/red-team/types.js +1 -0
- package/dist/noesis/gates/standards-review/index.d.ts +3 -0
- package/dist/noesis/gates/standards-review/index.js +2 -0
- package/dist/noesis/gates/standards-review/invoke.d.ts +5 -0
- package/dist/noesis/gates/standards-review/invoke.js +6 -0
- package/dist/noesis/gates/standards-review/prompt.d.ts +5 -0
- package/dist/noesis/gates/standards-review/prompt.js +26 -0
- package/dist/noesis/gates/standards-review/types.d.ts +20 -0
- package/dist/noesis/gates/standards-review/types.js +1 -0
- package/dist/noesis/gates/think-checkpoint/index.d.ts +3 -0
- package/dist/noesis/gates/think-checkpoint/index.js +2 -0
- package/dist/noesis/gates/think-checkpoint/invoke.d.ts +5 -0
- package/dist/noesis/gates/think-checkpoint/invoke.js +6 -0
- package/dist/noesis/gates/think-checkpoint/prompt.d.ts +5 -0
- package/dist/noesis/gates/think-checkpoint/prompt.js +28 -0
- package/dist/noesis/gates/think-checkpoint/types.d.ts +21 -0
- package/dist/noesis/gates/think-checkpoint/types.js +1 -0
- package/dist/noesis/index.d.ts +51 -0
- package/dist/noesis/index.js +27 -0
- package/dist/noesis/producers/cove-answers/index.d.ts +3 -0
- package/dist/noesis/producers/cove-answers/index.js +2 -0
- package/dist/noesis/producers/cove-answers/invoke.d.ts +5 -0
- package/dist/noesis/producers/cove-answers/invoke.js +6 -0
- package/dist/noesis/producers/cove-answers/prompt.d.ts +5 -0
- package/dist/noesis/producers/cove-answers/prompt.js +27 -0
- package/dist/noesis/producers/cove-answers/types.d.ts +32 -0
- package/dist/noesis/producers/cove-answers/types.js +1 -0
- package/dist/noesis/producers/cove-questions/index.d.ts +3 -0
- package/dist/noesis/producers/cove-questions/index.js +2 -0
- package/dist/noesis/producers/cove-questions/invoke.d.ts +5 -0
- package/dist/noesis/producers/cove-questions/invoke.js +6 -0
- package/dist/noesis/producers/cove-questions/prompt.d.ts +5 -0
- package/dist/noesis/producers/cove-questions/prompt.js +26 -0
- package/dist/noesis/producers/cove-questions/types.d.ts +17 -0
- package/dist/noesis/producers/cove-questions/types.js +1 -0
- package/dist/noesis/producers/decompose/index.d.ts +3 -0
- package/dist/noesis/producers/decompose/index.js +2 -0
- package/dist/noesis/producers/decompose/invoke.d.ts +5 -0
- package/dist/noesis/producers/decompose/invoke.js +6 -0
- package/dist/noesis/producers/decompose/prompt.d.ts +22 -0
- package/dist/noesis/producers/decompose/prompt.js +68 -0
- package/dist/noesis/producers/decompose/types.d.ts +41 -0
- package/dist/noesis/producers/decompose/types.js +1 -0
- package/dist/noesis/producers/discriminating-test/index.d.ts +3 -0
- package/dist/noesis/producers/discriminating-test/index.js +2 -0
- package/dist/noesis/producers/discriminating-test/invoke.d.ts +5 -0
- package/dist/noesis/producers/discriminating-test/invoke.js +6 -0
- package/dist/noesis/producers/discriminating-test/prompt.d.ts +5 -0
- package/dist/noesis/producers/discriminating-test/prompt.js +67 -0
- package/dist/noesis/producers/discriminating-test/types.d.ts +32 -0
- package/dist/noesis/producers/discriminating-test/types.js +1 -0
- package/dist/noesis/producers/plan-candidates/index.d.ts +3 -0
- package/dist/noesis/producers/plan-candidates/index.js +2 -0
- package/dist/noesis/producers/plan-candidates/invoke.d.ts +5 -0
- package/dist/noesis/producers/plan-candidates/invoke.js +6 -0
- package/dist/noesis/producers/plan-candidates/prompt.d.ts +5 -0
- package/dist/noesis/producers/plan-candidates/prompt.js +46 -0
- package/dist/noesis/producers/plan-candidates/types.d.ts +32 -0
- package/dist/noesis/producers/plan-candidates/types.js +1 -0
- package/dist/noesis/producers/qn-brief/index.d.ts +3 -0
- package/dist/noesis/producers/qn-brief/index.js +2 -0
- package/dist/noesis/producers/qn-brief/invoke.d.ts +5 -0
- package/dist/noesis/producers/qn-brief/invoke.js +6 -0
- package/dist/noesis/producers/qn-brief/prompt.d.ts +12 -0
- package/dist/noesis/producers/qn-brief/prompt.js +65 -0
- package/dist/noesis/producers/qn-brief/types.d.ts +42 -0
- package/dist/noesis/producers/qn-brief/types.js +1 -0
- package/dist/noesis/producers/toulmin/answer.d.ts +18 -0
- package/dist/noesis/producers/toulmin/answer.js +87 -0
- package/dist/noesis/producers/toulmin/index.d.ts +5 -0
- package/dist/noesis/producers/toulmin/index.js +4 -0
- package/dist/noesis/producers/toulmin/invoke.d.ts +18 -0
- package/dist/noesis/producers/toulmin/invoke.js +53 -0
- package/dist/noesis/producers/toulmin/prompt.d.ts +12 -0
- package/dist/noesis/producers/toulmin/prompt.js +60 -0
- package/dist/noesis/producers/toulmin/render.d.ts +14 -0
- package/dist/noesis/producers/toulmin/render.js +82 -0
- package/dist/noesis/producers/toulmin/types.d.ts +126 -0
- package/dist/noesis/producers/toulmin/types.js +1 -0
- package/dist/noesis/question.d.ts +24 -0
- package/dist/noesis/question.js +37 -0
- package/dist/noesis/repair/reflection/index.d.ts +3 -0
- package/dist/noesis/repair/reflection/index.js +2 -0
- package/dist/noesis/repair/reflection/invoke.d.ts +5 -0
- package/dist/noesis/repair/reflection/invoke.js +6 -0
- package/dist/noesis/repair/reflection/prompt.d.ts +5 -0
- package/dist/noesis/repair/reflection/prompt.js +26 -0
- package/dist/noesis/repair/reflection/types.d.ts +17 -0
- package/dist/noesis/repair/reflection/types.js +1 -0
- package/dist/noesis/retry.d.ts +25 -0
- package/dist/noesis/retry.js +60 -0
- package/dist/noesis/route.d.ts +29 -0
- package/dist/noesis/route.js +69 -0
- package/dist/noesis/router/triage/index.d.ts +3 -0
- package/dist/noesis/router/triage/index.js +2 -0
- package/dist/noesis/router/triage/invoke.d.ts +31 -0
- package/dist/noesis/router/triage/invoke.js +76 -0
- package/dist/noesis/router/triage/prompt.d.ts +11 -0
- package/dist/noesis/router/triage/prompt.js +34 -0
- package/dist/noesis/router/triage/types.d.ts +70 -0
- package/dist/noesis/router/triage/types.js +1 -0
- package/dist/noesis/run/artifacts.d.ts +12 -0
- package/dist/noesis/run/artifacts.js +31 -0
- package/dist/noesis/run/errors.d.ts +38 -0
- package/dist/noesis/run/errors.js +55 -0
- package/dist/noesis/run/index.d.ts +6 -0
- package/dist/noesis/run/index.js +4 -0
- package/dist/noesis/run/ledger.d.ts +110 -0
- package/dist/noesis/run/ledger.js +184 -0
- package/dist/noesis/run/loop.d.ts +15 -0
- package/dist/noesis/run/loop.js +91 -0
- package/dist/noesis/run/plan.d.ts +18 -0
- package/dist/noesis/run/plan.js +39 -0
- package/dist/noesis/run/produce.d.ts +50 -0
- package/dist/noesis/run/produce.js +114 -0
- package/dist/noesis/run/redo.d.ts +24 -0
- package/dist/noesis/run/redo.js +41 -0
- package/dist/noesis/run/result.d.ts +5 -0
- package/dist/noesis/run/result.js +51 -0
- package/dist/noesis/run/run.d.ts +4 -0
- package/dist/noesis/run/run.js +73 -0
- package/dist/noesis/run/stages/classify.d.ts +7 -0
- package/dist/noesis/run/stages/classify.js +23 -0
- package/dist/noesis/run/stages/direct.d.ts +6 -0
- package/dist/noesis/run/stages/direct.js +8 -0
- package/dist/noesis/run/stages/full.d.ts +14 -0
- package/dist/noesis/run/stages/full.js +21 -0
- package/dist/noesis/run/stages/index.d.ts +5 -0
- package/dist/noesis/run/stages/index.js +5 -0
- package/dist/noesis/run/stages/retrieve.d.ts +13 -0
- package/dist/noesis/run/stages/retrieve.js +38 -0
- package/dist/noesis/run/stages/standard.d.ts +12 -0
- package/dist/noesis/run/stages/standard.js +19 -0
- package/dist/noesis/run/state.d.ts +26 -0
- package/dist/noesis/run/state.js +13 -0
- package/dist/noesis/run/stream.d.ts +28 -0
- package/dist/noesis/run/stream.js +33 -0
- package/dist/noesis/run/verify.d.ts +27 -0
- package/dist/noesis/run/verify.js +78 -0
- package/dist/noesis/slugs.d.ts +16 -0
- package/dist/noesis/slugs.js +46 -0
- package/dist/noesis/stage.d.ts +56 -0
- package/dist/noesis/stage.js +52 -0
- package/dist/noesis/started.d.ts +18 -0
- package/dist/noesis/started.js +39 -0
- package/dist/noesis/types.d.ts +167 -0
- package/dist/noesis/types.js +1 -0
- package/dist/noesis/usage.d.ts +49 -0
- package/dist/noesis/usage.js +56 -0
- package/dist/noesis/verify/index.d.ts +2 -0
- package/dist/noesis/verify/index.js +1 -0
- package/dist/noesis/verify/types.d.ts +54 -0
- package/dist/noesis/verify/types.js +1 -0
- package/dist/noesis/verify/verify.d.ts +36 -0
- package/dist/noesis/verify/verify.js +94 -0
- package/package.json +59 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export const NO_USAGE = {
|
|
2
|
+
inputTokens: 0,
|
|
3
|
+
outputTokens: 0,
|
|
4
|
+
cacheReadTokens: 0,
|
|
5
|
+
cacheWriteTokens: 0,
|
|
6
|
+
citationTokens: 0,
|
|
7
|
+
reasoningTokens: 0,
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Sums two costs without inventing one.
|
|
11
|
+
*
|
|
12
|
+
* Undefined on both sides stays undefined; a priced call landing beside an
|
|
13
|
+
* unpriced one gives the priced total, which is a floor rather than a fiction.
|
|
14
|
+
*/
|
|
15
|
+
const addCost = (a, b) => a === undefined && b === undefined ? undefined : (a ?? 0) + (b ?? 0);
|
|
16
|
+
/** Every token field filled, so a caller never has to guard one. Cost stays absent when it is. */
|
|
17
|
+
export const usageOf = (reported) => ({
|
|
18
|
+
inputTokens: reported.inputTokens ?? 0,
|
|
19
|
+
outputTokens: reported.outputTokens ?? 0,
|
|
20
|
+
cacheReadTokens: reported.cacheReadTokens ?? 0,
|
|
21
|
+
cacheWriteTokens: reported.cacheWriteTokens ?? 0,
|
|
22
|
+
citationTokens: reported.citationTokens ?? 0,
|
|
23
|
+
reasoningTokens: reported.reasoningTokens ?? 0,
|
|
24
|
+
...(reported.costMicros === undefined ? {} : { costMicros: reported.costMicros }),
|
|
25
|
+
});
|
|
26
|
+
export const addUsage = (total, next) => ({
|
|
27
|
+
inputTokens: total.inputTokens + (next.inputTokens ?? 0),
|
|
28
|
+
outputTokens: total.outputTokens + (next.outputTokens ?? 0),
|
|
29
|
+
cacheReadTokens: total.cacheReadTokens + (next.cacheReadTokens ?? 0),
|
|
30
|
+
cacheWriteTokens: total.cacheWriteTokens + (next.cacheWriteTokens ?? 0),
|
|
31
|
+
citationTokens: total.citationTokens + (next.citationTokens ?? 0),
|
|
32
|
+
reasoningTokens: total.reasoningTokens + (next.reasoningTokens ?? 0),
|
|
33
|
+
...(() => {
|
|
34
|
+
const cost = addCost(total.costMicros, next.costMicros);
|
|
35
|
+
return cost === undefined ? {} : { costMicros: cost };
|
|
36
|
+
})(),
|
|
37
|
+
});
|
|
38
|
+
/** Every token the call is billed for, however the provider split them. */
|
|
39
|
+
export const billableTokens = (usage) => usage.inputTokens +
|
|
40
|
+
usage.outputTokens +
|
|
41
|
+
usage.cacheReadTokens +
|
|
42
|
+
usage.cacheWriteTokens +
|
|
43
|
+
usage.citationTokens +
|
|
44
|
+
usage.reasoningTokens;
|
|
45
|
+
/** What the run is known to have cost, in micro-USD, or undefined where nothing priced it. */
|
|
46
|
+
export const spend = (usage) => usage.costMicros;
|
|
47
|
+
/**
|
|
48
|
+
* One price for several calls: undefined unless at least one of them was priced.
|
|
49
|
+
*
|
|
50
|
+
* The cascade in 6C runs a tier at a time, so a run can hold several prices
|
|
51
|
+
* still in flight. Summing them with `?? 0` alone would turn "nobody priced
|
|
52
|
+
* any of these" into a confident zero.
|
|
53
|
+
*/
|
|
54
|
+
export const totalCost = (costs) => costs.some((cost) => cost !== undefined)
|
|
55
|
+
? costs.reduce((sum, cost) => sum + (cost ?? 0), 0)
|
|
56
|
+
: undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { blind, compare, render, SETTLED_WITHOUT_TOOLS } from "./verify.js";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { CheckedBy } from "../producers/cove-answers/index.js";
|
|
2
|
+
import type { ClaimType } from "../producers/cove-questions/index.js";
|
|
3
|
+
/** One claim, the question that tested it, and what came back. */
|
|
4
|
+
export interface Checked {
|
|
5
|
+
id: string;
|
|
6
|
+
claim: string;
|
|
7
|
+
claim_type: ClaimType;
|
|
8
|
+
question: string;
|
|
9
|
+
/** Empty where the check came back unknown. */
|
|
10
|
+
answer: string;
|
|
11
|
+
confidence: number;
|
|
12
|
+
unknown: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* When the fact was true, as 5B dated it. Null where it is time-invariant,
|
|
15
|
+
* and null where the check found nothing — there is no date for a non-fact.
|
|
16
|
+
*/
|
|
17
|
+
as_of?: string | null;
|
|
18
|
+
/** How the check was settled, as the run can actually support it. */
|
|
19
|
+
checked_by?: CheckedBy;
|
|
20
|
+
/** What 5B said, where `compare()` had to correct it. */
|
|
21
|
+
claimed_by?: CheckedBy;
|
|
22
|
+
/** False where the check could not settle the claim either way. */
|
|
23
|
+
settled: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The two halves of stage 5, put back together.
|
|
27
|
+
*
|
|
28
|
+
* Every list here is a count or a missing id — nothing judges whether an answer
|
|
29
|
+
* agrees with its claim, which is the reading 5C and 6A are for.
|
|
30
|
+
*/
|
|
31
|
+
export interface Verification {
|
|
32
|
+
checked: Checked[];
|
|
33
|
+
/** Questions 5A asked that 5B never answered. */
|
|
34
|
+
unanswered: string[];
|
|
35
|
+
/** Ids 5B answered that 5A never asked — the pairing has gone wrong. */
|
|
36
|
+
unasked: string[];
|
|
37
|
+
/** Claims no check settled: unknown, or below the floor. */
|
|
38
|
+
unsettled: string[];
|
|
39
|
+
/** Claims 5A said nothing could settle. */
|
|
40
|
+
unverifiable: string[];
|
|
41
|
+
/**
|
|
42
|
+
* Ids where 5B claimed a provenance the run could not have had.
|
|
43
|
+
*
|
|
44
|
+
* Not an error and not a dropped check: the answer still counts, the
|
|
45
|
+
* provenance on it has been corrected to `knowledge`, and the id is recorded
|
|
46
|
+
* here so a stage reading the verification can see that the record was
|
|
47
|
+
* repaired rather than believed.
|
|
48
|
+
*
|
|
49
|
+
* A reply that named no provenance is absent from this list. Saying nothing
|
|
50
|
+
* is not the same as claiming a tool, and a gate told otherwise would refuse
|
|
51
|
+
* over a correction nobody made.
|
|
52
|
+
*/
|
|
53
|
+
overclaimed: string[];
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { CheckedBy, CoveAnswers } from "../producers/cove-answers/index.js";
|
|
2
|
+
import type { CoveQuestions } from "../producers/cove-questions/index.js";
|
|
3
|
+
import type { Verification } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* What a check can honestly have been settled by when 5B is given no tools.
|
|
6
|
+
*
|
|
7
|
+
* `coveAnswers` is called with a client, a model and a question — there is no
|
|
8
|
+
* `ToolBus` on that call, so parametric memory is the only thing the stage can
|
|
9
|
+
* have used. Every other value in the enum is reachable only by passing a wider
|
|
10
|
+
* set to `compare()`, which is the caller saying it wired the tools up.
|
|
11
|
+
*/
|
|
12
|
+
export declare const SETTLED_WITHOUT_TOOLS: ReadonlySet<CheckedBy>;
|
|
13
|
+
/**
|
|
14
|
+
* The questions as 5B is allowed to see them: ids and questions, nothing else.
|
|
15
|
+
*
|
|
16
|
+
* `claim_it_tests` and `claim_type` are stripped here rather than trusted to a
|
|
17
|
+
* prompt. Answering blind is the whole reason 5A and 5B are two stages, and a
|
|
18
|
+
* stage that can read the claim will answer the claim.
|
|
19
|
+
*/
|
|
20
|
+
export declare function blind(questions: CoveQuestions): string;
|
|
21
|
+
/**
|
|
22
|
+
* 5A and 5B paired back together by id.
|
|
23
|
+
*
|
|
24
|
+
* In code because it has to be: whatever does this sees both the claim and the
|
|
25
|
+
* answer that was written without it, and a model given both is no longer a
|
|
26
|
+
* blind check of anything.
|
|
27
|
+
*
|
|
28
|
+
* A reply that named no provenance at all is not overclaiming. `checked_by` is
|
|
29
|
+
* required by the schema and nothing checks a reply against it on the way back,
|
|
30
|
+
* so an absent one is the model being terse rather than the stage claiming a
|
|
31
|
+
* tool it never had — it settles to `knowledge`, which is the floor anyway, and
|
|
32
|
+
* is not reported as a correction nobody made.
|
|
33
|
+
*/
|
|
34
|
+
export declare function compare(questions: CoveQuestions, answers: CoveAnswers, floor?: number, settledBy?: ReadonlySet<CheckedBy>): Verification;
|
|
35
|
+
/** The verification as a stage reads it. */
|
|
36
|
+
export declare function render(verification: Verification): string;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const DEFAULT_FLOOR = 0.6;
|
|
2
|
+
/**
|
|
3
|
+
* What a check can honestly have been settled by when 5B is given no tools.
|
|
4
|
+
*
|
|
5
|
+
* `coveAnswers` is called with a client, a model and a question — there is no
|
|
6
|
+
* `ToolBus` on that call, so parametric memory is the only thing the stage can
|
|
7
|
+
* have used. Every other value in the enum is reachable only by passing a wider
|
|
8
|
+
* set to `compare()`, which is the caller saying it wired the tools up.
|
|
9
|
+
*/
|
|
10
|
+
export const SETTLED_WITHOUT_TOOLS = new Set(["knowledge"]);
|
|
11
|
+
/**
|
|
12
|
+
* The questions as 5B is allowed to see them: ids and questions, nothing else.
|
|
13
|
+
*
|
|
14
|
+
* `claim_it_tests` and `claim_type` are stripped here rather than trusted to a
|
|
15
|
+
* prompt. Answering blind is the whole reason 5A and 5B are two stages, and a
|
|
16
|
+
* stage that can read the claim will answer the claim.
|
|
17
|
+
*/
|
|
18
|
+
export function blind(questions) {
|
|
19
|
+
return questions.questions.map((q) => `${q.id}. ${q.question}`).join("\n");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 5A and 5B paired back together by id.
|
|
23
|
+
*
|
|
24
|
+
* In code because it has to be: whatever does this sees both the claim and the
|
|
25
|
+
* answer that was written without it, and a model given both is no longer a
|
|
26
|
+
* blind check of anything.
|
|
27
|
+
*
|
|
28
|
+
* A reply that named no provenance at all is not overclaiming. `checked_by` is
|
|
29
|
+
* required by the schema and nothing checks a reply against it on the way back,
|
|
30
|
+
* so an absent one is the model being terse rather than the stage claiming a
|
|
31
|
+
* tool it never had — it settles to `knowledge`, which is the floor anyway, and
|
|
32
|
+
* is not reported as a correction nobody made.
|
|
33
|
+
*/
|
|
34
|
+
export function compare(questions, answers, floor = DEFAULT_FLOOR, settledBy = SETTLED_WITHOUT_TOOLS) {
|
|
35
|
+
const replies = new Map(answers.answers.map((a) => [a.id, a]));
|
|
36
|
+
const asked = new Set(questions.questions.map((q) => q.id));
|
|
37
|
+
const checked = [];
|
|
38
|
+
const unanswered = [];
|
|
39
|
+
const overclaimed = [];
|
|
40
|
+
for (const question of questions.questions) {
|
|
41
|
+
const reply = replies.get(question.id);
|
|
42
|
+
if (!reply) {
|
|
43
|
+
unanswered.push(question.id);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const claimed = reply.checked_by;
|
|
47
|
+
const overclaiming = !!claimed && !settledBy.has(claimed);
|
|
48
|
+
if (overclaiming)
|
|
49
|
+
overclaimed.push(question.id);
|
|
50
|
+
checked.push({
|
|
51
|
+
id: question.id,
|
|
52
|
+
claim: question.claim_it_tests,
|
|
53
|
+
claim_type: question.claim_type,
|
|
54
|
+
question: question.question,
|
|
55
|
+
answer: reply.answer,
|
|
56
|
+
confidence: reply.confidence,
|
|
57
|
+
unknown: reply.unknown,
|
|
58
|
+
as_of: reply.unknown ? null : reply.as_of,
|
|
59
|
+
checked_by: overclaiming || !claimed ? "knowledge" : claimed,
|
|
60
|
+
...(overclaiming ? { claimed_by: claimed } : {}),
|
|
61
|
+
settled: !reply.unknown && reply.confidence >= floor,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
checked,
|
|
66
|
+
unanswered,
|
|
67
|
+
unasked: answers.answers.filter((a) => !asked.has(a.id)).map((a) => a.id),
|
|
68
|
+
unsettled: checked.filter((c) => !c.settled).map((c) => c.claim),
|
|
69
|
+
unverifiable: questions.unverifiable_claims,
|
|
70
|
+
overclaimed,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const line = (c) => `${c.id}. ${c.claim}\n asked: ${c.question}\n found: ${c.unknown ? "nothing" : c.answer} (${c.settled ? "settled" : "unsettled"}, confidence ${c.confidence})${c.as_of ? `\n as of: ${c.as_of}` : ""}`;
|
|
74
|
+
/** The verification as a stage reads it. */
|
|
75
|
+
export function render(verification) {
|
|
76
|
+
const parts = [
|
|
77
|
+
`<checks>\n${verification.checked.length
|
|
78
|
+
? verification.checked.map(line).join("\n\n")
|
|
79
|
+
: "Nothing was checked."}\n</checks>`,
|
|
80
|
+
];
|
|
81
|
+
if (verification.unsettled.length) {
|
|
82
|
+
parts.push(`<unsettled>\n${verification.unsettled.join("\n")}\n</unsettled>`);
|
|
83
|
+
}
|
|
84
|
+
if (verification.unverifiable.length) {
|
|
85
|
+
parts.push(`<unverifiable>\n${verification.unverifiable.join("\n")}\n</unverifiable>`);
|
|
86
|
+
}
|
|
87
|
+
if (verification.overclaimed.length) {
|
|
88
|
+
parts.push(`<overclaimed>\nrecorded as knowledge — the check had no tool to use: ${verification.overclaimed.join(", ")}\n</overclaimed>`);
|
|
89
|
+
}
|
|
90
|
+
if (verification.unanswered.length || verification.unasked.length) {
|
|
91
|
+
parts.push(`<mismatched>\nnever answered: ${verification.unanswered.join(", ") || "none"}\nnever asked: ${verification.unasked.join(", ") || "none"}\n</mismatched>`);
|
|
92
|
+
}
|
|
93
|
+
return parts.join("\n\n");
|
|
94
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@spendgraph/workflows",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Ready-made workflows assembled from the spendgraph packages.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/fnLog0/spendgraph.git",
|
|
9
|
+
"directory": "packages/workflows"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/fnLog0/spendgraph#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/fnLog0/spendgraph/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"llm",
|
|
17
|
+
"agent",
|
|
18
|
+
"workflow",
|
|
19
|
+
"orchestration"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"import": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@spendgraph/harness": "^0.2.0",
|
|
37
|
+
"@spendgraph/llms": "^0.2.0",
|
|
38
|
+
"@spendgraph/prompt": "^0.2.0",
|
|
39
|
+
"@spendgraph/tools": "^0.2.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc -p tsconfig.json",
|
|
43
|
+
"prebuild": "npm run build --workspace @spendgraph/harness --workspace @spendgraph/llms --workspace @spendgraph/prompt --workspace @spendgraph/tools",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"eval": "vitest run --config evals/vitest.config.mts",
|
|
46
|
+
"eval:typecheck": "tsc -p evals/tsconfig.json"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@locusgraph/client": "^0.8.1",
|
|
50
|
+
"@spendgraph/evals": "^0.2.0",
|
|
51
|
+
"typescript": "^5"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=18"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
}
|
|
59
|
+
}
|