anchor-ai-sdk 0.8.11 → 0.8.13
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 +45 -1
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +1 -0
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/types.d.ts +20 -0
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/agents/workflow/index.d.ts +49 -0
- package/dist/agents/workflow/index.d.ts.map +1 -0
- package/dist/agents/workflow/index.js +46 -0
- package/dist/agents/workflow/index.js.map +1 -0
- package/dist/agents/workflow/prompt.d.ts +11 -0
- package/dist/agents/workflow/prompt.d.ts.map +1 -0
- package/dist/agents/workflow/prompt.js +25 -0
- package/dist/agents/workflow/prompt.js.map +1 -0
- package/dist/engine/context.d.ts +9 -3
- package/dist/engine/context.d.ts.map +1 -1
- package/dist/engine/context.js +23 -3
- package/dist/engine/context.js.map +1 -1
- package/dist/engine/loop.d.ts.map +1 -1
- package/dist/engine/loop.js +163 -21
- package/dist/engine/loop.js.map +1 -1
- package/dist/engine/types.d.ts +15 -0
- package/dist/engine/types.d.ts.map +1 -1
- package/dist/engine/workflow.d.ts +74 -0
- package/dist/engine/workflow.d.ts.map +1 -0
- package/dist/engine/workflow.js +125 -0
- package/dist/engine/workflow.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/llm/index.d.ts +2 -0
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +1 -0
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/openai-compatible.d.ts +9 -1
- package/dist/llm/openai-compatible.d.ts.map +1 -1
- package/dist/llm/openai-compatible.js +53 -2
- package/dist/llm/openai-compatible.js.map +1 -1
- package/dist/llm/types.d.ts +25 -0
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/schema.d.ts +64 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +166 -0
- package/dist/schema.js.map +1 -0
- package/dist/tools/finish.d.ts +15 -0
- package/dist/tools/finish.d.ts.map +1 -1
- package/dist/tools/finish.js +39 -12
- package/dist/tools/finish.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -576,6 +576,50 @@ Validate inputs and enforce permissions in your implementation.
|
|
|
576
576
|
**[Tools and schemas](https://anchor-sdk.dev/docs.html#tools)** ·
|
|
577
577
|
**[Runnable SDK examples](https://github.com/hrithikkoduri/anchor-ai-sdk/tree/main/examples)**
|
|
578
578
|
|
|
579
|
+
### Headless workflows: `workflowAgent`
|
|
580
|
+
|
|
581
|
+
For background jobs that never talk to a user — environment setup, migrations
|
|
582
|
+
— build a workflow agent. Nobody reads its prose and nobody answers its
|
|
583
|
+
questions, so the engine enforces the contract instead of the conversation:
|
|
584
|
+
|
|
585
|
+
```js
|
|
586
|
+
import { bashTool, editFileTool, readFileTool, runAgent, userTurn, workflowAgent } from "anchor-ai-sdk";
|
|
587
|
+
|
|
588
|
+
const environment = workflowAgent({
|
|
589
|
+
name: "environment",
|
|
590
|
+
brief: "Infer how to install and boot this app. Write the recipe to .sailor/run.sh and prove it boots.",
|
|
591
|
+
tools: [bashTool, readFileTool, editFileTool],
|
|
592
|
+
check: { command: "bash .sailor/run.sh --check", description: "the app boots and answers on its port" },
|
|
593
|
+
output: {
|
|
594
|
+
name: "recipe",
|
|
595
|
+
schema: {
|
|
596
|
+
type: "object",
|
|
597
|
+
properties: { install: { type: "string" }, start: { type: "string" }, port: { type: "integer" } },
|
|
598
|
+
required: ["install", "start", "port"],
|
|
599
|
+
additionalProperties: false,
|
|
600
|
+
},
|
|
601
|
+
},
|
|
602
|
+
budget: { maxTurns: 30 },
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
const result = await runAgent(userTurn("Repository: acme/web"), { llm, sandbox, agent: environment });
|
|
606
|
+
if (result.ok) console.log(result.output); // { install, start, port }, already validated
|
|
607
|
+
else console.log(result.reason); // e.g. "budget_exhausted"
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
- `finish` is the only exit, and it is accepted only when the latest `bash` run
|
|
611
|
+
of `check.command` in this run passed (exit 0, no timeout) and no file was
|
|
612
|
+
edited after it. The check must be the command's final step — a `cd dir &&`
|
|
613
|
+
prefix is fine; `|| true`, a pipe, or `echo` does not count. A rejected
|
|
614
|
+
finish, or a prose reply, comes back as a corrective message and the run continues.
|
|
615
|
+
- `output` (a JSON schema or a zod schema) is validated inside that gate and
|
|
616
|
+
returned as `result.output`.
|
|
617
|
+
- The conversational nudges (silent-tool, verbose-turn, prose checkpoint) are
|
|
618
|
+
off; the repeated-call, empty-turn, and capped-reply corrections stay on.
|
|
619
|
+
- Running out of any budget, `maxTurns` included, ends with `ok: false` and
|
|
620
|
+
`reason: "budget_exhausted"`.
|
|
621
|
+
- `ask_questions` is refused, and so is `EngineOptions.inbox`: a workflow run is one-shot.
|
|
622
|
+
|
|
579
623
|
## Configure the runtime, not another loop
|
|
580
624
|
|
|
581
625
|
| Capability | Your controls |
|
|
@@ -753,7 +797,7 @@ and an extraction failure, not the full benchmark or a general superiority claim
|
|
|
753
797
|
|
|
754
798
|
## Status and contributing
|
|
755
799
|
|
|
756
|
-
**Early alpha, 0.x. Source version: 0.8.
|
|
800
|
+
**Early alpha, 0.x. Source version: 0.8.12; latest published release: v0.8.12.** Pin exact versions and test your
|
|
757
801
|
integration. Provider and runtime features are version-specific; the current
|
|
758
802
|
source may be ahead of the installed package. Daytona, agent teams, context
|
|
759
803
|
reset, MCP, and consumer skill bundles remain roadmap work in the reviewed
|
package/dist/agents/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC"}
|
package/dist/agents/index.js
CHANGED
package/dist/agents/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC"}
|
package/dist/agents/types.d.ts
CHANGED
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
* same `strategy` + `tools` options it always took, and explicit options win
|
|
11
11
|
* per-field. Custom agents are just objects built from the same primitives.
|
|
12
12
|
*/
|
|
13
|
+
import type { BudgetLimits } from "../engine/budgets.js";
|
|
13
14
|
import type { AgentStrategy } from "../engine/strategy.js";
|
|
15
|
+
import type { GuardrailConfig } from "../engine/types.js";
|
|
16
|
+
import type { WorkflowContract } from "../engine/workflow.js";
|
|
14
17
|
import type { ReasoningEffort } from "../llm/types.js";
|
|
15
18
|
import type { Tool } from "../tools/types.js";
|
|
16
19
|
export interface Agent {
|
|
@@ -30,5 +33,22 @@ export interface Agent {
|
|
|
30
33
|
* `EngineOptions.reasoningEffort` wins; absent, the provider default applies.
|
|
31
34
|
*/
|
|
32
35
|
reasoningEffort?: ReasoningEffort;
|
|
36
|
+
/**
|
|
37
|
+
* Guardrail defaults this bundle suggests. Merged per field under
|
|
38
|
+
* `EngineOptions.guardrails`: an explicit field wins, an absent one falls
|
|
39
|
+
* back to the bundle, then to the engine default.
|
|
40
|
+
*/
|
|
41
|
+
guardrails?: GuardrailConfig;
|
|
42
|
+
/**
|
|
43
|
+
* Budget defaults this bundle suggests, merged per field under
|
|
44
|
+
* `EngineOptions.budgets` the same way.
|
|
45
|
+
*/
|
|
46
|
+
budgets?: Partial<BudgetLimits>;
|
|
47
|
+
/**
|
|
48
|
+
* Present only on workflow bundles (`workflowAgent`): a headless run with a
|
|
49
|
+
* check-gated, schema-validated finish. The engine enforces it; see
|
|
50
|
+
* engine/workflow.ts.
|
|
51
|
+
*/
|
|
52
|
+
workflow?: WorkflowContract;
|
|
33
53
|
}
|
|
34
54
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/agents/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAE9C,MAAM,WAAW,KAAK;IACpB,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,QAAQ,EAAE,aAAa,CAAC;IACxB,6EAA6E;IAC7E,KAAK,EAAE,IAAI,EAAE,CAAC;IACd;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACjC;;;OAGG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/agents/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAE9C,MAAM,WAAW,KAAK;IACpB,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,QAAQ,EAAE,aAAa,CAAC;IACxB,6EAA6E;IAC7E,KAAK,EAAE,IAAI,EAAE,CAAC;IACd;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACjC;;;OAGG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC;;;;OAIG;IACH,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAChC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CAC7B"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* workflowAgent — a headless agent for background jobs that never talk to a
|
|
3
|
+
* user (environment setup, migrations, scheduled maintenance).
|
|
4
|
+
*
|
|
5
|
+
* It is an ordinary bundle (strategy + tools + defaults) plus a
|
|
6
|
+
* `WorkflowContract` the engine enforces with seams it already has:
|
|
7
|
+
*
|
|
8
|
+
* - the system prompt says plainly that no one reads the output and no one
|
|
9
|
+
* answers; the brief is the whole task;
|
|
10
|
+
* - the conversational nudges (silent-tool, verbose-turn, prose checkpoint)
|
|
11
|
+
* are off by default; turn-lifecycle guardrails stay on;
|
|
12
|
+
* - `finish` is the only exit, accepted only after the check passed in this
|
|
13
|
+
* run's own tool log, and only with a schema-valid `output`, which lands on
|
|
14
|
+
* `AgentResult.output`;
|
|
15
|
+
* - running out of budget (`maxTurns` included) ends as `budget_exhausted`,
|
|
16
|
+
* a failure;
|
|
17
|
+
* - `ask_questions` is refused, and so are inbox chains and steering.
|
|
18
|
+
*/
|
|
19
|
+
import type { Tool } from "../../tools/types.js";
|
|
20
|
+
import type { JSONSchema, OutputSchema } from "../../schema.js";
|
|
21
|
+
import type { Agent } from "../types.js";
|
|
22
|
+
export { buildWorkflowPrompt } from "./prompt.js";
|
|
23
|
+
export interface WorkflowSpec {
|
|
24
|
+
/** Short name for logs and traces: "environment", "migration", … */
|
|
25
|
+
name: string;
|
|
26
|
+
/** Everything the run must achieve. There is no conversation: this must be complete. */
|
|
27
|
+
brief: string;
|
|
28
|
+
/** Domain tools; coding tools are composed by the caller. */
|
|
29
|
+
tools: Tool[];
|
|
30
|
+
/** The proof the run must produce before it may finish. */
|
|
31
|
+
check: {
|
|
32
|
+
command: string;
|
|
33
|
+
description: string;
|
|
34
|
+
};
|
|
35
|
+
/** The structured result the run must return; validated, not suggested. */
|
|
36
|
+
output?: {
|
|
37
|
+
name: string;
|
|
38
|
+
schema: OutputSchema;
|
|
39
|
+
/** Shown to the model when `schema` is a zod schema without `toJSONSchema()`. */
|
|
40
|
+
jsonSchema?: JSONSchema;
|
|
41
|
+
description?: string;
|
|
42
|
+
};
|
|
43
|
+
budget?: {
|
|
44
|
+
maxTurns?: number;
|
|
45
|
+
maxOutputTokens?: number;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export declare function workflowAgent(spec: WorkflowSpec): Agent;
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agents/workflow/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,WAAW,YAAY;IAC3B,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,wFAAwF;IACxF,KAAK,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,2DAA2D;IAC3D,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD,2EAA2E;IAC3E,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,YAAY,CAAC;QACrB,iFAAiF;QACjF,UAAU,CAAC,EAAE,UAAU,CAAC;QACxB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,MAAM,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1D;AAID,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,KAAK,CA8CvD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { buildWorkflowPrompt } from "./prompt.js";
|
|
2
|
+
export { buildWorkflowPrompt } from "./prompt.js";
|
|
3
|
+
const QUESTION_TOOL = "ask_questions";
|
|
4
|
+
export function workflowAgent(spec) {
|
|
5
|
+
if (!spec.name.trim())
|
|
6
|
+
throw new Error("workflowAgent: name is required");
|
|
7
|
+
if (!spec.brief.trim())
|
|
8
|
+
throw new Error(`workflowAgent "${spec.name}": brief is required — it is the whole task`);
|
|
9
|
+
if (!spec.check.command.trim())
|
|
10
|
+
throw new Error(`workflowAgent "${spec.name}": check.command is required`);
|
|
11
|
+
if (spec.tools.some((tool) => tool.definition.name === QUESTION_TOOL))
|
|
12
|
+
throw new Error(`workflowAgent "${spec.name}": ${QUESTION_TOOL} is not allowed — no one answers a workflow's questions`);
|
|
13
|
+
if (!spec.tools.some((tool) => tool.definition.name === "bash"))
|
|
14
|
+
throw new Error(`workflowAgent "${spec.name}": a bash tool is required — the check is proven by running it`);
|
|
15
|
+
const { maxTurns, maxOutputTokens } = spec.budget ?? {};
|
|
16
|
+
if (maxTurns !== undefined && (!Number.isInteger(maxTurns) || maxTurns <= 0))
|
|
17
|
+
throw new Error(`workflowAgent "${spec.name}": budget.maxTurns must be a positive integer`);
|
|
18
|
+
const strategy = {
|
|
19
|
+
name: spec.name,
|
|
20
|
+
phases: [{ id: "run", goal: "achieve the brief and prove it with the check" }],
|
|
21
|
+
requiredTools: ["bash"],
|
|
22
|
+
requiresSandbox: true,
|
|
23
|
+
systemPrompt: ({ context, summary }) => buildWorkflowPrompt(spec, {
|
|
24
|
+
...(context ? { context } : {}),
|
|
25
|
+
...(summary ? { summary } : {}),
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
const workflow = {
|
|
29
|
+
check: { ...spec.check },
|
|
30
|
+
...(spec.output ? { output: { ...spec.output } } : {}),
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
name: spec.name,
|
|
34
|
+
strategy,
|
|
35
|
+
tools: [...spec.tools],
|
|
36
|
+
...(maxOutputTokens !== undefined ? { maxOutputTokens } : {}),
|
|
37
|
+
...(maxTurns !== undefined ? { budgets: { maxSteps: maxTurns } } : {}),
|
|
38
|
+
guardrails: {
|
|
39
|
+
toolOnlyNudgeLimit: false,
|
|
40
|
+
verboseTurnLimit: false,
|
|
41
|
+
proseCheckpoint: false,
|
|
42
|
+
},
|
|
43
|
+
workflow,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=index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AAC,CAAC,EAAE,CAAC;QACtE,UAAU,EAAE;YACV,kBAAkB,EAAE,KAAK;YACzB,gBAAgB,EAAE,KAAK;YACvB,eAAe,EAAE,KAAK;SACvB;QACD,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The workflow system prompt. Short on purpose: the brief is the task, and the
|
|
3
|
+
* rest only removes the conversational habits a chat-trained model brings
|
|
4
|
+
* (asking, narrating, ending on a reply).
|
|
5
|
+
*/
|
|
6
|
+
import type { WorkflowSpec } from "./index.js";
|
|
7
|
+
export declare function buildWorkflowPrompt(spec: Pick<WorkflowSpec, "name" | "brief" | "check" | "output">, extra?: {
|
|
8
|
+
context?: string;
|
|
9
|
+
summary?: string;
|
|
10
|
+
}): string;
|
|
11
|
+
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../src/agents/workflow/prompt.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC,EAC/D,KAAK,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,GACjD,MAAM,CAuBR"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function buildWorkflowPrompt(spec, extra = {}) {
|
|
2
|
+
const output = spec.output
|
|
3
|
+
? `\n\n# Output\nReturn \`${spec.output.name}\` as the \`output\` argument of \`finish\`. It is validated against its schema; an invalid value is rejected and you must fix it.` +
|
|
4
|
+
(spec.output.description ? `\n${spec.output.description}` : "")
|
|
5
|
+
: "";
|
|
6
|
+
const context = extra.context ? `\n\n# Workspace\n${extra.context}` : "";
|
|
7
|
+
const summary = extra.summary
|
|
8
|
+
? `\n\n# Summary of earlier work in this run\n${extra.summary}`
|
|
9
|
+
: "";
|
|
10
|
+
return `You are running the "${spec.name}" workflow: a background job with no conversation.
|
|
11
|
+
|
|
12
|
+
No one is reading your output. No one will answer a question. Do not ask for permission, confirmation, or clarification, and do not narrate. The brief below is complete: where it leaves a choice open, decide from what you observe in the workspace and keep going.
|
|
13
|
+
|
|
14
|
+
Work only through tool calls. A prose reply does not end the run. The only way to end it is \`finish\`, and \`finish\` is accepted only after the check below has passed in this run. Report results as data in \`finish\`, not as prose.
|
|
15
|
+
|
|
16
|
+
# Brief
|
|
17
|
+
${spec.brief.trim()}
|
|
18
|
+
|
|
19
|
+
# Check
|
|
20
|
+
${spec.check.description.trim()}
|
|
21
|
+
Run it with bash exactly as written (a \`cd <dir> &&\` prefix is fine):
|
|
22
|
+
\`${spec.check.command}\`
|
|
23
|
+
A pass counts only if it is the latest run of the check and no file was edited after it.${output}${context}${summary}`;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../src/agents/workflow/prompt.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,mBAAmB,CACjC,IAA+D,EAC/D,KAAK,GAA2C,EAAE;IAElD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM;QACxB,CAAC,CAAC,0BAA0B,IAAI,CAAC,MAAM,CAAC,IAAI,oIAAoI;YAC9K,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjE,CAAC,CAAC,EAAE,CAAC;IACP,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,oBAAoB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACzE,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO;QAC3B,CAAC,CAAC,8CAA8C,KAAK,CAAC,OAAO,EAAE;QAC/D,CAAC,CAAC,EAAE,CAAC;IACP,OAAO,wBAAwB,IAAI,CAAC,IAAI;;;;;;;EAOxC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;;;EAGjB,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE;;IAE3B,IAAI,CAAC,KAAK,CAAC,OAAO;0FACoE,MAAM,GAAG,OAAO,GAAG,OAAO,EAAE,CAAC;AACvH,CAAC"}
|
package/dist/engine/context.d.ts
CHANGED
|
@@ -6,12 +6,18 @@
|
|
|
6
6
|
* turn was pure tool calls. Keeping these in one place means the loop never
|
|
7
7
|
* hand-rolls protocol details.
|
|
8
8
|
*/
|
|
9
|
-
import type { LLMMessage, LLMResponse } from "../llm/types.js";
|
|
10
|
-
|
|
9
|
+
import type { LLMMessage, LLMResponse, ReasoningPassback } from "../llm/types.js";
|
|
10
|
+
/**
|
|
11
|
+
* With `passback` on, the turn keeps its reasoning so the next request in the
|
|
12
|
+
* tool loop can replay it; off, the message is exactly content + tool calls.
|
|
13
|
+
*/
|
|
14
|
+
export declare function assistantMessage(response: LLMResponse, passback?: ReasoningPassback): LLMMessage;
|
|
11
15
|
export declare function toolResultMessage(toolCallId: string, content: string): LLMMessage;
|
|
12
16
|
export declare function userMessage(content: string, images?: LLMMessage["images"]): LLMMessage;
|
|
13
17
|
/** Working memory contains real conversation and observations, not system
|
|
14
18
|
* prompts or internal orchestration messages. No prefix guessing: a user's
|
|
15
|
-
* text is still their text even if it happens to start with "PHASE:".
|
|
19
|
+
* text is still their text even if it happens to start with "PHASE:".
|
|
20
|
+
* Replayed reasoning is in-run state: it is only needed within the tool loop
|
|
21
|
+
* that produced it, so it is neither persisted nor revived. */
|
|
16
22
|
export declare function conversationHistory(messages: LLMMessage[]): LLMMessage[];
|
|
17
23
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/engine/context.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/engine/context.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAEzB;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,WAAW,EACrB,QAAQ,GAAE,iBAAyB,GAClC,UAAU,CAeZ;AAED,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GACd,UAAU,CAEZ;AAED,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,GAC5B,UAAU,CAMZ;AAED;;;;+DAI+D;AAC/D,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,CAMxE"}
|
package/dist/engine/context.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* With `passback` on, the turn keeps its reasoning so the next request in the
|
|
3
|
+
* tool loop can replay it; off, the message is exactly content + tool calls.
|
|
4
|
+
*/
|
|
5
|
+
export function assistantMessage(response, passback = false) {
|
|
2
6
|
return {
|
|
3
7
|
role: "assistant",
|
|
4
8
|
content: response.text === "" && response.toolCalls.length > 0
|
|
5
9
|
? null
|
|
6
10
|
: response.text,
|
|
7
11
|
tool_calls: response.toolCalls.length > 0 ? response.toolCalls : undefined,
|
|
12
|
+
...(passback && response.reasoning
|
|
13
|
+
? { reasoning: response.reasoning }
|
|
14
|
+
: {}),
|
|
15
|
+
...(passback && response.reasoningDetails?.length
|
|
16
|
+
? { reasoningDetails: response.reasoningDetails }
|
|
17
|
+
: {}),
|
|
8
18
|
};
|
|
9
19
|
}
|
|
10
20
|
export function toolResultMessage(toolCallId, content) {
|
|
@@ -19,8 +29,18 @@ export function userMessage(content, images) {
|
|
|
19
29
|
}
|
|
20
30
|
/** Working memory contains real conversation and observations, not system
|
|
21
31
|
* prompts or internal orchestration messages. No prefix guessing: a user's
|
|
22
|
-
* text is still their text even if it happens to start with "PHASE:".
|
|
32
|
+
* text is still their text even if it happens to start with "PHASE:".
|
|
33
|
+
* Replayed reasoning is in-run state: it is only needed within the tool loop
|
|
34
|
+
* that produced it, so it is neither persisted nor revived. */
|
|
23
35
|
export function conversationHistory(messages) {
|
|
24
|
-
return messages
|
|
36
|
+
return messages
|
|
37
|
+
.filter((message) => message.role !== "system" && message.origin !== "engine")
|
|
38
|
+
.map(withoutReasoning);
|
|
39
|
+
}
|
|
40
|
+
function withoutReasoning(message) {
|
|
41
|
+
if (message.reasoning === undefined && message.reasoningDetails === undefined)
|
|
42
|
+
return message;
|
|
43
|
+
const { reasoning: _reasoning, reasoningDetails: _details, ...rest } = message;
|
|
44
|
+
return rest;
|
|
25
45
|
}
|
|
26
46
|
//# sourceMappingURL=context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/engine/context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/engine/context.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAAqB,EACrB,QAAQ,GAAsB,KAAK;IAEnC,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,OAAO,EACL,QAAQ,CAAC,IAAI,KAAK,EAAE,IAAI,QAAQ,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC;YACnD,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,QAAQ,CAAC,IAAI;QACnB,UAAU,EAAE,QA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AAU,EAAE,gBAAgB,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAC/E,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../../src/engine/loop.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../../src/engine/loop.ts"],"names":[],"mappings":"AA+GA,OAAO,KAAK,EACV,QAAQ,EACR,aAAa,EACb,WAAW,EAIZ,MAAM,YAAY,CAAC;AAUpB,YAAY,EACV,QAAQ,EACR,aAAa,EACb,WAAW,EACX,YAAY,EACZ,eAAe,EACf,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAwmFtC,gFAAgF;AAChF;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CASpE;AAuHD,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,QAAQ,EACf,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,WAAW,CAAC,CAStB"}
|