@archmax-ai/harness 0.8.0 → 1.0.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 +58 -14
- package/dist/agent.d.ts +4 -4
- package/dist/agent.js +4 -4
- package/dist/assembly/compose.d.ts +5 -24
- package/dist/assembly/compose.js +40 -41
- package/dist/assembly/compose.js.map +1 -1
- package/dist/assembly/delegation-registry.js +3 -14
- package/dist/assembly/delegation-registry.js.map +1 -1
- package/dist/assembly/index.d.ts +18 -15
- package/dist/assembly/index.js +50 -32
- package/dist/assembly/index.js.map +1 -1
- package/dist/assembly/plain.js +1 -2
- package/dist/assembly/plain.js.map +1 -1
- package/dist/authoring-skill/archmax-harness/README.md +5 -5
- package/dist/authoring-skill/archmax-harness/SKILL.md +72 -30
- package/dist/authoring-skill/archmax-harness/references/backend-integration.md +35 -23
- package/dist/authoring-skill/archmax-harness/references/cases.md +44 -10
- package/dist/authoring-skill/archmax-harness/references/{hook-and-test-scripts.md → code-state-and-test-scripts.md} +617 -313
- package/dist/authoring-skill/archmax-harness/references/code-states-and-scripts.md +115 -0
- package/dist/authoring-skill/archmax-harness/references/diagnostics.md +40 -7
- package/dist/authoring-skill/archmax-harness/references/wiring.md +19 -10
- package/dist/authoring-skill/archmax-harness/references/workflow-schema.md +416 -276
- package/dist/authoring-skill/archmax-harness/references/workflow-yaml.md +161 -62
- package/dist/cli/state-flow.d.ts +1 -1
- package/dist/cli/state-flow.js +18 -28
- package/dist/cli/state-flow.js.map +1 -1
- package/dist/cli/turn.d.ts +1 -1
- package/dist/cli/turn.js +2 -3
- package/dist/cli/turn.js.map +1 -1
- package/dist/core/clock.d.ts +26 -0
- package/dist/core/clock.js +64 -0
- package/dist/core/clock.js.map +1 -0
- package/dist/core/code-description.d.ts +3 -3
- package/dist/core/code-description.js +3 -3
- package/dist/core/deepagents.d.ts +5 -5
- package/dist/core/deepagents.js +4 -4
- package/dist/core/events.d.ts +23 -42
- package/dist/core/events.js +21 -24
- package/dist/core/events.js.map +1 -1
- package/dist/core/message-readers.d.ts +22 -2
- package/dist/core/message-readers.js +31 -0
- package/dist/core/message-readers.js.map +1 -1
- package/dist/core/messages.d.ts +1 -23
- package/dist/core/messages.js +2 -35
- package/dist/core/messages.js.map +1 -1
- package/dist/core/mounts.js +3 -3
- package/dist/core/platform-prompt.generated.js +1 -1
- package/dist/core/platform-prompt.generated.js.map +1 -1
- package/dist/core/session-zone.d.ts +1 -1
- package/dist/core/session-zone.js +1 -1
- package/dist/core/workspace-context.d.ts +1 -1
- package/dist/core/workspace.d.ts +1 -1
- package/dist/core/workspace.js +1 -1
- package/dist/core/zones.d.ts +4 -4
- package/dist/core/zones.js +5 -5
- package/dist/core/zones.js.map +1 -1
- package/dist/env.d.ts +9 -9
- package/dist/index.d.ts +3 -7
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/kernel/kernel.d.ts +31 -61
- package/dist/kernel/kernel.js +57 -114
- package/dist/kernel/kernel.js.map +1 -1
- package/dist/machine/allow.d.ts +17 -2
- package/dist/machine/allow.js +16 -6
- package/dist/machine/allow.js.map +1 -1
- package/dist/machine/lint-spec.js +68 -12
- package/dist/machine/lint-spec.js.map +1 -1
- package/dist/machine/machine.d.ts +39 -16
- package/dist/machine/machine.js +72 -49
- package/dist/machine/machine.js.map +1 -1
- package/dist/machine/spec-schema.d.ts +34 -179
- package/dist/machine/spec-schema.js +93 -106
- package/dist/machine/spec-schema.js.map +1 -1
- package/dist/machine/tool-names.d.ts +34 -10
- package/dist/machine/tool-names.js +41 -10
- package/dist/machine/tool-names.js.map +1 -1
- package/dist/machine/tool-paths.d.ts +6 -0
- package/dist/machine/tool-paths.js +10 -0
- package/dist/machine/tool-paths.js.map +1 -1
- package/dist/machine/types.d.ts +14 -38
- package/dist/machine/types.js.map +1 -1
- package/dist/machine/validate-spec.d.ts +1 -1
- package/dist/machine/variables.d.ts +2 -0
- package/dist/machine/variables.js.map +1 -1
- package/dist/public/sandbox.d.ts +62 -66
- package/dist/public/sandbox.js +22 -23
- package/dist/public/sandbox.js.map +1 -1
- package/dist/public/spec.d.ts +12 -19
- package/dist/public/spec.js +11 -19
- package/dist/public/spec.js.map +1 -1
- package/dist/runtime/contract.d.ts +11 -12
- package/dist/runtime/contract.js +16 -16
- package/dist/runtime/contract.js.map +1 -1
- package/dist/sandbox/assets/parts/code-state.js +17 -0
- package/dist/sandbox/executor.d.ts +25 -7
- package/dist/sandbox/executor.js +56 -47
- package/dist/sandbox/executor.js.map +1 -1
- package/dist/sandbox/imports.d.ts +10 -10
- package/dist/sandbox/imports.js +11 -11
- package/dist/sandbox/imports.js.map +1 -1
- package/dist/sandbox/prelude.d.ts +5 -6
- package/dist/sandbox/prelude.js +38 -35
- package/dist/sandbox/prelude.js.map +1 -1
- package/dist/sandbox/ptc-gateway.d.ts +19 -18
- package/dist/sandbox/ptc-gateway.js +26 -22
- package/dist/sandbox/ptc-gateway.js.map +1 -1
- package/dist/sessions/operations.js +4 -5
- package/dist/sessions/operations.js.map +1 -1
- package/dist/sessions/resume.d.ts +12 -7
- package/dist/sessions/resume.js +12 -9
- package/dist/sessions/resume.js.map +1 -1
- package/dist/sessions/summary.d.ts +1 -1
- package/dist/testing/assertions.js +9 -4
- package/dist/testing/assertions.js.map +1 -1
- package/dist/testing/case-document.d.ts +2 -0
- package/dist/testing/case-document.js.map +1 -1
- package/dist/testing/case-schema.d.ts +1 -1
- package/dist/testing/case-schema.js +17 -1
- package/dist/testing/case-schema.js.map +1 -1
- package/dist/testing/driver.d.ts +4 -0
- package/dist/testing/driver.js +22 -3
- package/dist/testing/driver.js.map +1 -1
- package/dist/testing/grade.js +3 -3
- package/dist/testing/grade.js.map +1 -1
- package/dist/testing/interpreter.d.ts +2 -2
- package/dist/testing/interpreter.js +1 -0
- package/dist/testing/interpreter.js.map +1 -1
- package/dist/testing/runner.d.ts +2 -2
- package/dist/validate/validate.d.ts +1 -1
- package/dist/validate/validate.js +39 -70
- package/dist/validate/validate.js.map +1 -1
- package/dist/workflow/automated-controls.d.ts +63 -0
- package/dist/workflow/automated-controls.js +158 -0
- package/dist/workflow/automated-controls.js.map +1 -0
- package/dist/workflow/automated.d.ts +112 -0
- package/dist/workflow/automated.js +163 -0
- package/dist/workflow/automated.js.map +1 -0
- package/dist/workflow/checkpointer.d.ts +7 -0
- package/dist/workflow/checkpointer.js +28 -0
- package/dist/workflow/checkpointer.js.map +1 -1
- package/dist/workflow/code-state.d.ts +46 -0
- package/dist/workflow/code-state.js +26 -0
- package/dist/workflow/code-state.js.map +1 -0
- package/dist/workflow/control-tools.d.ts +54 -23
- package/dist/workflow/control-tools.js +121 -77
- package/dist/workflow/control-tools.js.map +1 -1
- package/dist/workflow/file-values.d.ts +4 -4
- package/dist/workflow/file-values.js +1 -1
- package/dist/workflow/file-values.js.map +1 -1
- package/dist/workflow/governance.d.ts +13 -22
- package/dist/workflow/governance.js +51 -87
- package/dist/workflow/governance.js.map +1 -1
- package/dist/workflow/grader-state.d.ts +55 -0
- package/dist/workflow/grader-state.js +182 -0
- package/dist/workflow/grader-state.js.map +1 -0
- package/dist/workflow/history.d.ts +11 -0
- package/dist/workflow/history.js +64 -0
- package/dist/workflow/history.js.map +1 -0
- package/dist/workflow/middleware.d.ts +14 -17
- package/dist/workflow/middleware.js +106 -74
- package/dist/workflow/middleware.js.map +1 -1
- package/dist/workflow/move-events.d.ts +21 -0
- package/dist/workflow/move-events.js +20 -0
- package/dist/workflow/move-events.js.map +1 -0
- package/dist/workflow/parks.d.ts +9 -2
- package/dist/workflow/parks.js +16 -8
- package/dist/workflow/parks.js.map +1 -1
- package/dist/workflow/paths.d.ts +9 -9
- package/dist/workflow/paths.js +19 -19
- package/dist/workflow/paths.js.map +1 -1
- package/dist/workflow/render-prompt.d.ts +7 -5
- package/dist/workflow/render-prompt.js +22 -37
- package/dist/workflow/render-prompt.js.map +1 -1
- package/dist/workflow/signature-checks.d.ts +2 -2
- package/dist/workflow/snapshot.js +5 -29
- package/dist/workflow/snapshot.js.map +1 -1
- package/dist/workflow/state.d.ts +19 -6
- package/dist/workflow/state.js +24 -8
- package/dist/workflow/state.js.map +1 -1
- package/dist/workflow/sub-workflow.d.ts +3 -3
- package/dist/workflow/tool-service.d.ts +1 -9
- package/dist/workflow/tool-service.js +21 -24
- package/dist/workflow/tool-service.js.map +1 -1
- package/dist/workflow/turn-boundary.d.ts +2 -2
- package/dist/workflow/turn-boundary.js +10 -7
- package/dist/workflow/turn-boundary.js.map +1 -1
- package/dist/workflow/turn-runner.js +30 -2
- package/dist/workflow/turn-runner.js.map +1 -1
- package/package.json +1 -1
- package/skills/archmax-harness/README.md +5 -5
- package/skills/archmax-harness/SKILL.md +72 -30
- package/skills/archmax-harness/references/backend-integration.md +35 -23
- package/skills/archmax-harness/references/cases.md +44 -10
- package/skills/archmax-harness/references/{hook-and-test-scripts.md → code-state-and-test-scripts.md} +617 -313
- package/skills/archmax-harness/references/code-states-and-scripts.md +115 -0
- package/skills/archmax-harness/references/diagnostics.md +40 -7
- package/skills/archmax-harness/references/wiring.md +19 -10
- package/skills/archmax-harness/references/workflow-schema.md +416 -276
- package/skills/archmax-harness/references/workflow-yaml.md +161 -62
- package/dist/authoring-skill/archmax-harness/references/hooks-and-scripts.md +0 -88
- package/dist/lifecycle/hook-shape.d.ts +0 -44
- package/dist/lifecycle/hook-shape.js +0 -66
- package/dist/lifecycle/hook-shape.js.map +0 -1
- package/dist/lifecycle/runner.d.ts +0 -183
- package/dist/lifecycle/runner.js +0 -373
- package/dist/lifecycle/runner.js.map +0 -1
- package/dist/lifecycle/transcript.d.ts +0 -27
- package/dist/lifecycle/transcript.js +0 -43
- package/dist/lifecycle/transcript.js.map +0 -1
- package/dist/rubrics/rubrics.d.ts +0 -135
- package/dist/rubrics/rubrics.js +0 -145
- package/dist/rubrics/rubrics.js.map +0 -1
- package/dist/sandbox/assets/parts/core.js +0 -22
- package/dist/sandbox/assets/parts/lifecycle-hook.js +0 -47
- package/dist/sandbox/bridge.d.ts +0 -16
- package/dist/sandbox/bridge.js +0 -95
- package/dist/sandbox/bridge.js.map +0 -1
- package/skills/archmax-harness/references/hooks-and-scripts.md +0 -88
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A grader state's run: an isolated grader subagent — its own model, its own
|
|
3
|
+
* prompt, its own messages — that judges the session and decides where it goes.
|
|
4
|
+
*
|
|
5
|
+
* Isolated in three ways. It reads the session only through its tools
|
|
6
|
+
* (`archmax_get_history` above all), and nothing it says enters the session's
|
|
7
|
+
* transcript. Its tokens are tagged `nostream`, so they never stream as the
|
|
8
|
+
* session's text. And it compiles with no checkpointer, so it writes nothing into
|
|
9
|
+
* the session's thread. What it decided reaches the session as the step
|
|
10
|
+
* recorder's decision, which the orchestrator (`automated.ts`) commits.
|
|
11
|
+
*
|
|
12
|
+
* Its tools are its state's surface, already governed by the PTC gateway on the
|
|
13
|
+
* `agent` origin; this module adds what a model's calls get on the agent's own
|
|
14
|
+
* path — `${{…}}` argument substitution, and a refused or failed call answered
|
|
15
|
+
* as an error the model can read rather than thrown — and ends the loop the
|
|
16
|
+
* moment a decision is recorded.
|
|
17
|
+
*/
|
|
18
|
+
import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
19
|
+
import type { StructuredTool } from "@langchain/core/tools";
|
|
20
|
+
import type { WorkflowEventEmitter } from "../core/events.js";
|
|
21
|
+
import { type PricingTable, type UsageSummary } from "../core/usage.js";
|
|
22
|
+
import type { WorkflowMachine } from "../machine/machine.js";
|
|
23
|
+
import type { StepRecorder } from "./automated-controls.js";
|
|
24
|
+
/**
|
|
25
|
+
* What every grader is told before its state's criteria: what it is, how it reads
|
|
26
|
+
* the session, and the two calls it decides with. Compiled in, like the platform
|
|
27
|
+
* prompt: a grader's contract is the runtime's, its criteria are the author's.
|
|
28
|
+
*/
|
|
29
|
+
export declare const GRADER_PREAMBLE = "# Grader\n\nYou are the grader of one state of a workflow session. You do not talk to anyone:\nyou judge the session's work against the criteria below and decide where the\nsession goes next.\n\n1. Read the session with `archmax_get_history`: every message so far, and the trail of\n states it moved through and why. Read files or variables when the criteria need them.\n2. Decide by calling `archmax_advance({ \"to\": \"<slug>\", \"reason\": \"<what you found>\" })` with\n one of the transitions listed in your task. The reason is what the next state reads:\n when you send work back, say exactly what has to change.\n3. When the work cannot be accepted and must not be retried \u2014 your criteria say when \u2014\n call `archmax_raise({ \"code\": \"<short-token>\", \"reason\": \"<why>\" })` instead: it ends the\n session as failed.\n\nMake exactly one of those two calls, then stop. Text you write is read by no one.\n\n## Criteria";
|
|
30
|
+
/** The task a grader is handed: where it stands, and the transitions it chooses from. */
|
|
31
|
+
export declare function graderTask(machine: WorkflowMachine, state: string): string;
|
|
32
|
+
export interface GraderStateRun {
|
|
33
|
+
machine: WorkflowMachine;
|
|
34
|
+
emit: WorkflowEventEmitter;
|
|
35
|
+
pricing?: PricingTable;
|
|
36
|
+
state: string;
|
|
37
|
+
model: BaseChatModel;
|
|
38
|
+
/** The model's id, for usage events, when the instance exposes one. */
|
|
39
|
+
modelId?: string;
|
|
40
|
+
/** The grader state's tools, governed (controls included). */
|
|
41
|
+
tools: StructuredTool[];
|
|
42
|
+
recorder: StepRecorder;
|
|
43
|
+
/** The turn's abort signal: a cancelled turn cancels the grader. */
|
|
44
|
+
signal?: AbortSignal;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Run a grader state's subagent. Settles with the error that stopped it, if one
|
|
48
|
+
* did — an exhausted `budget.maxTurns`, an expired `budget.timeoutMs`, a model
|
|
49
|
+
* or runtime failure — and with its usage across every model call. A cancelled
|
|
50
|
+
* turn is not the grader's failure: its abort propagates.
|
|
51
|
+
*/
|
|
52
|
+
export declare function runGraderState(run: GraderStateRun): Promise<{
|
|
53
|
+
error?: string;
|
|
54
|
+
usage?: UsageSummary;
|
|
55
|
+
}>;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { HumanMessage, ToolMessage } from "@langchain/core/messages";
|
|
2
|
+
import { isCommand, isGraphBubbleUp } from "@langchain/langgraph";
|
|
3
|
+
import { createAgent, createMiddleware, tool } from "langchain";
|
|
4
|
+
import { DEFAULT_RECURSION_LIMIT } from "../core/deepagents.js";
|
|
5
|
+
import { contentToString, isAiMessage } from "../core/messages.js";
|
|
6
|
+
import { addSummaries, extractUsage, summarizeUsage } from "../core/usage.js";
|
|
7
|
+
import { ADVANCE_TOOL, GET_HISTORY_TOOL, RAISE_TOOL, isWorkflowToolName } from "../machine/tool-names.js";
|
|
8
|
+
import { resolveArguments } from "../machine/variables.js";
|
|
9
|
+
import { PtcGovernanceError } from "../sandbox/ptc-gateway.js";
|
|
10
|
+
import { unresolvedArgumentMessage } from "./control-tools.js";
|
|
11
|
+
import { renderTransitions } from "./render-prompt.js";
|
|
12
|
+
import { blockedMessage } from "./tool-service.js";
|
|
13
|
+
/**
|
|
14
|
+
* What every grader is told before its state's criteria: what it is, how it reads
|
|
15
|
+
* the session, and the two calls it decides with. Compiled in, like the platform
|
|
16
|
+
* prompt: a grader's contract is the runtime's, its criteria are the author's.
|
|
17
|
+
*/
|
|
18
|
+
export const GRADER_PREAMBLE = `# Grader
|
|
19
|
+
|
|
20
|
+
You are the grader of one state of a workflow session. You do not talk to anyone:
|
|
21
|
+
you judge the session's work against the criteria below and decide where the
|
|
22
|
+
session goes next.
|
|
23
|
+
|
|
24
|
+
1. Read the session with \`${GET_HISTORY_TOOL}\`: every message so far, and the trail of
|
|
25
|
+
states it moved through and why. Read files or variables when the criteria need them.
|
|
26
|
+
2. Decide by calling \`${ADVANCE_TOOL}({ "to": "<slug>", "reason": "<what you found>" })\` with
|
|
27
|
+
one of the transitions listed in your task. The reason is what the next state reads:
|
|
28
|
+
when you send work back, say exactly what has to change.
|
|
29
|
+
3. When the work cannot be accepted and must not be retried — your criteria say when —
|
|
30
|
+
call \`${RAISE_TOOL}({ "code": "<short-token>", "reason": "<why>" })\` instead: it ends the
|
|
31
|
+
session as failed.
|
|
32
|
+
|
|
33
|
+
Make exactly one of those two calls, then stop. Text you write is read by no one.
|
|
34
|
+
|
|
35
|
+
## Criteria`;
|
|
36
|
+
/** The task a grader is handed: where it stands, and the transitions it chooses from. */
|
|
37
|
+
export function graderTask(machine, state) {
|
|
38
|
+
return [
|
|
39
|
+
`You are grading the session in the grader state \`${state}\`.`,
|
|
40
|
+
`Transitions — choose one with \`${ADVANCE_TOOL}\`:`,
|
|
41
|
+
...renderTransitions(machine, state),
|
|
42
|
+
].join("\n\n");
|
|
43
|
+
}
|
|
44
|
+
/** The tag LangGraph's message stream skips: a grader's tokens are not the session's text. */
|
|
45
|
+
const NO_STREAM_TAG = "langsmith:nostream";
|
|
46
|
+
/** The text a tool's settled value reads as, for the grader's tool answer. */
|
|
47
|
+
function answerText(value) {
|
|
48
|
+
if (typeof value === "string")
|
|
49
|
+
return value;
|
|
50
|
+
if (value instanceof ToolMessage)
|
|
51
|
+
return contentToString(value.content);
|
|
52
|
+
if (isCommand(value)) {
|
|
53
|
+
const messages = value.update?.messages ?? [];
|
|
54
|
+
const answer = [...messages].reverse().find((m) => m instanceof ToolMessage);
|
|
55
|
+
if (answer)
|
|
56
|
+
return contentToString(answer.content);
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
return JSON.stringify(value) ?? String(value);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return String(value);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The grader's own instance of a governed tool: same name, description and
|
|
67
|
+
* schema, invoked with plain arguments. The grader's tool node hands a tool a
|
|
68
|
+
* tool call and its own config; the governed tool takes arguments and runs on
|
|
69
|
+
* the session's turn config, which the gateway supplies.
|
|
70
|
+
*/
|
|
71
|
+
function graderTool(governed) {
|
|
72
|
+
return tool(async (args) => answerText(await governed.invoke(args)), {
|
|
73
|
+
name: governed.name,
|
|
74
|
+
description: governed.description,
|
|
75
|
+
schema: governed.schema,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Run a grader state's subagent. Settles with the error that stopped it, if one
|
|
80
|
+
* did — an exhausted `budget.maxTurns`, an expired `budget.timeoutMs`, a model
|
|
81
|
+
* or runtime failure — and with its usage across every model call. A cancelled
|
|
82
|
+
* turn is not the grader's failure: its abort propagates.
|
|
83
|
+
*/
|
|
84
|
+
export async function runGraderState(run) {
|
|
85
|
+
const { machine, emit, recorder, state } = run;
|
|
86
|
+
const declared = machine.spec.states[state];
|
|
87
|
+
const maxTurns = declared?.budget?.maxTurns;
|
|
88
|
+
const timeoutMs = declared?.budget?.timeoutMs;
|
|
89
|
+
let usage;
|
|
90
|
+
let modelCalls = 0;
|
|
91
|
+
let exhausted;
|
|
92
|
+
const middleware = createMiddleware({
|
|
93
|
+
name: "GraderMiddleware",
|
|
94
|
+
beforeModel: {
|
|
95
|
+
canJumpTo: ["end"],
|
|
96
|
+
hook: () => {
|
|
97
|
+
// Decided: the run is over, with no further model call.
|
|
98
|
+
if (recorder.decision)
|
|
99
|
+
return { jumpTo: "end" };
|
|
100
|
+
if (maxTurns != null && modelCalls + 1 > maxTurns) {
|
|
101
|
+
exhausted = `grader state '${state}' exhausted its turn budget (maxTurns: ${maxTurns})`;
|
|
102
|
+
return { jumpTo: "end" };
|
|
103
|
+
}
|
|
104
|
+
modelCalls += 1;
|
|
105
|
+
return undefined;
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
afterModel: (stateView) => {
|
|
109
|
+
const last = stateView.messages?.at(-1);
|
|
110
|
+
if (!last || !isAiMessage(last))
|
|
111
|
+
return undefined;
|
|
112
|
+
const extracted = extractUsage(last);
|
|
113
|
+
if (!extracted)
|
|
114
|
+
return undefined;
|
|
115
|
+
const model = extracted.model ?? run.modelId;
|
|
116
|
+
const summary = summarizeUsage(extracted.usage, run.pricing, model);
|
|
117
|
+
emit({ type: "model-usage", state, ...summary, ...(model ? { model } : {}) });
|
|
118
|
+
usage = usage ? addSummaries(usage, summary) : summary;
|
|
119
|
+
return undefined;
|
|
120
|
+
},
|
|
121
|
+
wrapToolCall: async (request, handler) => {
|
|
122
|
+
const name = request.toolCall.name;
|
|
123
|
+
const callId = request.toolCall.id ?? "";
|
|
124
|
+
let call = request;
|
|
125
|
+
// `${{…}}` resolves against the session's variables as this run sees them,
|
|
126
|
+
// exactly as the agent's own arguments do; a delegation's are its params.
|
|
127
|
+
if (!isWorkflowToolName(name)) {
|
|
128
|
+
const substituted = resolveArguments((request.toolCall.args ?? {}), recorder.store());
|
|
129
|
+
if (!substituted.ok)
|
|
130
|
+
return blockedMessage(name, callId, unresolvedArgumentMessage(substituted));
|
|
131
|
+
call = { ...request, toolCall: { ...request.toolCall, args: substituted.args } };
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
return await handler(call);
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
if (isGraphBubbleUp(err) || run.signal?.aborted)
|
|
138
|
+
throw err;
|
|
139
|
+
const cause = err?.cause ?? err;
|
|
140
|
+
const message = String(cause?.message ?? cause);
|
|
141
|
+
if (cause instanceof PtcGovernanceError)
|
|
142
|
+
return blockedMessage(name, callId, message);
|
|
143
|
+
return new ToolMessage({ content: message, tool_call_id: callId, name, status: "error" });
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
const grader = createAgent({
|
|
148
|
+
model: run.model,
|
|
149
|
+
tools: run.tools.map(graderTool),
|
|
150
|
+
systemPrompt: `${GRADER_PREAMBLE}\n\n${declared?.instructions?.trim() ?? ""}`,
|
|
151
|
+
middleware: [middleware],
|
|
152
|
+
checkpointer: false,
|
|
153
|
+
name: `grader:${state}`,
|
|
154
|
+
});
|
|
155
|
+
const signals = [run.signal, timeoutMs != null ? AbortSignal.timeout(timeoutMs) : undefined].filter((signal) => signal !== undefined);
|
|
156
|
+
const signal = signals.length > 1 ? AbortSignal.any(signals) : signals[0];
|
|
157
|
+
try {
|
|
158
|
+
await grader.invoke({ messages: [new HumanMessage(graderTask(machine, state))] }, {
|
|
159
|
+
...(signal ? { signal } : {}),
|
|
160
|
+
tags: [NO_STREAM_TAG],
|
|
161
|
+
// A model call is up to four graph steps (before it, the call, after it,
|
|
162
|
+
// its tools): room for every call the budget allows, which the
|
|
163
|
+
// middleware enforces first; unbounded, a session's own limit.
|
|
164
|
+
recursionLimit: maxTurns != null ? 4 * maxTurns + 8 : DEFAULT_RECURSION_LIMIT,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
if (run.signal?.aborted)
|
|
169
|
+
throw err;
|
|
170
|
+
if (recorder.decision)
|
|
171
|
+
return { ...(usage ? { usage } : {}) };
|
|
172
|
+
const expired = timeoutMs != null && signal?.aborted;
|
|
173
|
+
return {
|
|
174
|
+
error: expired
|
|
175
|
+
? `grader state '${state}' exceeded its time budget (timeoutMs: ${timeoutMs})`
|
|
176
|
+
: `grader state '${state}' failed: ${err?.message ?? String(err)}`,
|
|
177
|
+
...(usage ? { usage } : {}),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
return { ...(exhausted && !recorder.decision ? { error: exhausted } : {}), ...(usage ? { usage } : {}) };
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=grader-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grader-state.js","sourceRoot":"","sources":["../../src/workflow/grader-state.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAErE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEnE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,c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G,CAAC,CAAC,CAAC,CAAC,uBAAuB;SAC9E,CACF,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO;YAAE,MAAM,GAAG,CAAC;QACnC,IAAI,QAAQ,CAAC,QAAQ;YAAE,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;QAC9D,MAAM,OAAO,GAAG,SAAS,IAAI,IAAI,IAAI,MAAM,EAAE,OAAO,CAAC;QACrD,OAAO;YACL,KAAK,EAAE,OAAO;gBACZ,CAAC,CAAC,iBAAiB,KAAK,0CAA0C,SAAS,GAAG;gBAC9E,CAAC,CAAC,iBAAiB,KAAK,aAAc,GAAa,EAAE,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE;YAC/E,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC5B,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,GAAG,CAAC,SAAS,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AAC3G,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HistoryMessage, SessionHistory } from "../public/sandbox.js";
|
|
2
|
+
export type { HistoryMessage, SessionHistory };
|
|
3
|
+
/**
|
|
4
|
+
* The transcript as plain messages, oldest first. A runtime note is carried in
|
|
5
|
+
* the transcript as a tool-call pair; only the half holding the text is kept,
|
|
6
|
+
* as one `runtime` entry. A tool result carries its text, the tool that
|
|
7
|
+
* produced it, and the id of the call it answers.
|
|
8
|
+
*/
|
|
9
|
+
export declare function historyMessages(messages: unknown[]): HistoryMessage[];
|
|
10
|
+
/** The history of the session whose checkpointed state this is. */
|
|
11
|
+
export declare function sessionHistory(state: unknown): SessionHistory;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A session's **history**: its whole transcript as plain messages and its whole
|
|
3
|
+
* trail — what an automated state reads with `archmax_get_history`, a grader
|
|
4
|
+
* and a code state's script alike, so both counting the same rounds read the
|
|
5
|
+
* same thing. Built from the checkpointed session, never from the request a
|
|
6
|
+
* summary shortened for the model.
|
|
7
|
+
*
|
|
8
|
+
* Nothing is windowed: a grader asked to give up after N send-backs has to see
|
|
9
|
+
* all N. What bounds it is the sandbox's result and memory quotas, and the
|
|
10
|
+
* grader model's context.
|
|
11
|
+
*/
|
|
12
|
+
import { contentToString, messageTypeOf, runtimeNoteKind } from "../core/messages.js";
|
|
13
|
+
import { readAuditTrail } from "./state.js";
|
|
14
|
+
const ROLE_BY_TYPE = {
|
|
15
|
+
human: "user",
|
|
16
|
+
ai: "assistant",
|
|
17
|
+
system: "system",
|
|
18
|
+
tool: "tool",
|
|
19
|
+
function: "tool",
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The transcript as plain messages, oldest first. A runtime note is carried in
|
|
23
|
+
* the transcript as a tool-call pair; only the half holding the text is kept,
|
|
24
|
+
* as one `runtime` entry. A tool result carries its text, the tool that
|
|
25
|
+
* produced it, and the id of the call it answers.
|
|
26
|
+
*/
|
|
27
|
+
export function historyMessages(messages) {
|
|
28
|
+
const out = [];
|
|
29
|
+
for (const raw of Array.isArray(messages) ? messages : []) {
|
|
30
|
+
const msg = raw;
|
|
31
|
+
const type = messageTypeOf(raw);
|
|
32
|
+
const text = contentToString(msg.content);
|
|
33
|
+
const note = runtimeNoteKind(raw);
|
|
34
|
+
if (note !== null) {
|
|
35
|
+
if (text.trim() === "")
|
|
36
|
+
continue;
|
|
37
|
+
out.push({ role: "runtime", text, note });
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const role = ROLE_BY_TYPE[type] ?? (type || "unknown");
|
|
41
|
+
const entry = { role, text };
|
|
42
|
+
const calls = msg.tool_calls;
|
|
43
|
+
if ((type === "ai" || type === "assistant") && Array.isArray(calls) && calls.length > 0) {
|
|
44
|
+
entry.toolCalls = calls.map((c) => {
|
|
45
|
+
const call = c;
|
|
46
|
+
return { ...(call.id == null ? {} : { id: String(call.id) }), name: String(call.name ?? ""), args: call.args ?? {} };
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (role === "tool") {
|
|
50
|
+
if (typeof msg.name === "string")
|
|
51
|
+
entry.tool = msg.name;
|
|
52
|
+
if (msg.tool_call_id != null)
|
|
53
|
+
entry.id = String(msg.tool_call_id);
|
|
54
|
+
}
|
|
55
|
+
out.push(entry);
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
/** The history of the session whose checkpointed state this is. */
|
|
60
|
+
export function sessionHistory(state) {
|
|
61
|
+
const messages = state?.messages;
|
|
62
|
+
return { messages: historyMessages(Array.isArray(messages) ? messages : []), trail: readAuditTrail(state) };
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/workflow/history.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtF,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAI5C,MAAM,YAAY,GAA2B;IAC3C,KAAK,EAAE,MAAM;IACb,EAAE,EAAE,WAAW;IACf,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,MAAM;CACjB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,QA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AAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;YACvH,CAAC,CAAC,CAAC;QACL,CAAC;QACD,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;YACpB,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ;gBAAE,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;YACxD,IAAI,GAAG,CAAC,YAAY,IAAI,IAAI;gBAAE,KAAK,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACpE,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,MAAM,QAAQ,GAAI,KAA4C,EAAE,QAAQ,CAAC;IACzE,OAAO,EAAE,QAAQ,EAAE,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;AAC9G,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { StructuredTool } from "@langchain/core/tools";
|
|
2
2
|
import type { AgentMiddleware } from "langchain";
|
|
3
|
-
import type {
|
|
3
|
+
import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
4
|
+
import { type ScriptExecutor } from "../sandbox/executor.js";
|
|
4
5
|
import type { PtcToolGateway } from "../sandbox/ptc-gateway.js";
|
|
5
|
-
import { LifecycleRunner, type HookExecutor, type HookScriptResolver } from "../lifecycle/runner.js";
|
|
6
6
|
import type { WorkflowMachine } from "../machine/machine.js";
|
|
7
|
-
import type { Rubric } from "../rubrics/rubrics.js";
|
|
8
7
|
import type { Workspace } from "../core/workspace.js";
|
|
9
8
|
import { type WorkflowEventHandler } from "../core/events.js";
|
|
10
9
|
import type { VariableStore } from "../machine/variables.js";
|
|
10
|
+
import type { CodeScriptResolver } from "./code-state.js";
|
|
11
11
|
import type { SubWorkflowDispatcher } from "./sub-workflow.js";
|
|
12
12
|
import type { GovernanceRule } from "../kernel/kernel.js";
|
|
13
13
|
import { type MountPrefixes } from "../core/mounts.js";
|
|
@@ -29,30 +29,27 @@ export interface WorkflowInstrumentation {
|
|
|
29
29
|
/** The governance middleware proper; assembled after {@link parkMiddleware}. */
|
|
30
30
|
middleware: AgentMiddleware;
|
|
31
31
|
tools: StructuredTool[];
|
|
32
|
-
lifecycle: LifecycleRunner;
|
|
33
32
|
/** Release every per-session resource (idempotent; safe for sessions that never ran). */
|
|
34
33
|
dispose(sessionId: string): void;
|
|
35
34
|
}
|
|
36
35
|
export interface WorkflowMiddlewareOptions {
|
|
37
36
|
machine: WorkflowMachine;
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
/** Runs a code state's script, reading it from the authoring backend. */
|
|
38
|
+
codeExecutor: ScriptExecutor;
|
|
39
|
+
/** Resolves a code state's declared `script:` to its authoring-backend path. */
|
|
40
|
+
resolveCodeScript: CodeScriptResolver;
|
|
41
|
+
/** The model a grader state runs on, and its id when the instance exposes one. */
|
|
42
|
+
graderModel(state: string): {
|
|
43
|
+
model: BaseChatModel;
|
|
44
|
+
id?: string;
|
|
45
|
+
};
|
|
43
46
|
/** Consumer rules, evaluated after the safety and `policy` rules, before per-state defaults. */
|
|
44
47
|
policyRules?: GovernanceRule[];
|
|
45
48
|
/** The workspace's resolved mount keys, so the kernel's read-only rule can classify authored paths. */
|
|
46
49
|
mountPrefixes?: MountPrefixes;
|
|
47
50
|
/** The workspace's skills: one table for what the kernel refuses, the prompt names, a listing returns. */
|
|
48
51
|
skills?: SkillRegistry;
|
|
49
|
-
/**
|
|
50
|
-
hookExecutors?: Record<string, HookExecutor>;
|
|
51
|
-
/** Script executor for lifecycle hooks, reading from the authoring backend. Defaults to {@link executor}. */
|
|
52
|
-
hookExecutor?: ScriptExecutor;
|
|
53
|
-
/** Resolves a hook's declared `script:` to its authoring-backend path. */
|
|
54
|
-
resolveHookScript?: HookScriptResolver;
|
|
55
|
-
/** Governs the `tools.*` calls hook scripts make and carries the live per-session context. */
|
|
52
|
+
/** Governs every call made outside the tool node — scripts', automated states' — and carries the live per-session context. */
|
|
56
53
|
ptcGateway?: PtcToolGateway;
|
|
57
54
|
/** Runs delegated machines. Omitted, a delegation call falls through to the tool's own body. */
|
|
58
55
|
subWorkflows?: SubWorkflowDispatcher;
|
|
@@ -85,7 +82,7 @@ export interface WorkflowMiddlewareOptions {
|
|
|
85
82
|
}
|
|
86
83
|
/**
|
|
87
84
|
* In-graph governance for the Deep Agent: the turn boundary, per-state tool
|
|
88
|
-
* disclosure and the kernel's verdict on every call,
|
|
85
|
+
* disclosure and the kernel's verdict on every call, the automated states, the
|
|
89
86
|
* control tools, budgets, `on_error` routing, and every park's commit, closing
|
|
90
87
|
* turn and suspension.
|
|
91
88
|
*/
|