@alveus-ai/std 0.1.48 → 0.1.50
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/dist/agents/basic-chat.js +2 -2
- package/dist/agents/goal.d.ts +114 -0
- package/dist/agents/goal.d.ts.map +1 -0
- package/dist/agents/goal.js +0 -0
- package/dist/agents/goal.js.map +1 -0
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +5 -0
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/react.js +1 -1
- package/dist/blobs/{32a1c173fef4627d2c39bdfa293253d6baa6f6d1d3c4f1f146994c80030af7d5.js → 2fff20a2f2145c537e470a4b1f067080ebf10460533b638dc77bf937ddd362f4.js} +1 -0
- package/dist/blobs/{ea02e7f577c9e420831c741a0b02ec15b1b5f76975074cf031d763ec263327d1.js → 66296bb746405ec02e83f2e1e6d40195d2a361ac1cfac57c037296e3fbfcdb26.js} +1 -0
- package/dist/blobs/91419052e0dfce9efb32220d83b3cc5d37c4fc9189273083345cbcebfccf6c9b.js +228 -0
- package/dist/blobs/{0caaf80d04fbe7c988c7c5961fca2260ac01d8a91c37281cf8a18a719794ff7d.js → fd2d75bca62956931b98463149236799bdf6f09ee9321240c9df7cf2eccbbea4.js} +32 -0
- package/examples/goal-agent.ts +79 -0
- package/package.json +1 -1
|
@@ -55,7 +55,7 @@ export function createChatAgent(systemPrompt, options = {}) {
|
|
|
55
55
|
};
|
|
56
56
|
}, {
|
|
57
57
|
name: name || 'chat-agent',
|
|
58
|
-
description: description || 'A basic chat agent', hash: "
|
|
58
|
+
description: description || 'A basic chat agent', hash: "2fff20a2f2145c537e470a4b1f067080ebf10460533b638dc77bf937ddd362f4",
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
@@ -87,7 +87,7 @@ export function createJsonChatAgent(systemPrompt, options = {}) {
|
|
|
87
87
|
return { data, raw: reply };
|
|
88
88
|
}, {
|
|
89
89
|
name: name || 'json-chat-agent',
|
|
90
|
-
description: description || 'A structured JSON chat agent', hash: "
|
|
90
|
+
description: description || 'A structured JSON chat agent', hash: "66296bb746405ec02e83f2e1e6d40195d2a361ac1cfac57c037296e3fbfcdb26",
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
//# sourceMappingURL=basic-chat.js.map
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Goal Agent — bounded, self-verifying objective completion.
|
|
3
|
+
*
|
|
4
|
+
* A goal agent repeatedly attempts an objective and, each cycle, scores the
|
|
5
|
+
* result against explicit criteria using pinned **scorers**. It completes only
|
|
6
|
+
* when every required criterion passes for a single candidate in a single
|
|
7
|
+
* cycle, or stops when a bounded limit is reached.
|
|
8
|
+
*
|
|
9
|
+
* The authoritative outcome of a goal run is the platform-served Completion
|
|
10
|
+
* Receipt — which pinned scorer measured which candidate, and what it returned
|
|
11
|
+
* — not this agent's own return value (which an agent could fake).
|
|
12
|
+
*/
|
|
13
|
+
import type { ExecutionContext, GoalAgentInput, GoalAgentResult, GoalCriterion, CriterionThreshold, VirtualAgent } from '@alveus-ai/core';
|
|
14
|
+
/** A criterion as stored in the normalized, pinned goal contract. */
|
|
15
|
+
export interface NormalizedCriterion {
|
|
16
|
+
id: string;
|
|
17
|
+
threshold?: CriterionThreshold;
|
|
18
|
+
/** Code identity of the scorer that measures this criterion. */
|
|
19
|
+
scorerHash: string;
|
|
20
|
+
/** Configuration passed to (and part of the identity of) that scorer. */
|
|
21
|
+
scorerConfig?: Record<string, unknown>;
|
|
22
|
+
/** Expected/reference value, for reference-based criteria. */
|
|
23
|
+
reference?: unknown;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Internal input to the goal controller: the normalized contract (criteria with
|
|
27
|
+
* pinned scorers, bounds) merged with the runtime `objective`.
|
|
28
|
+
*/
|
|
29
|
+
export interface GoalAgentLogicInput extends GoalAgentInput {
|
|
30
|
+
criteria: NormalizedCriterion[];
|
|
31
|
+
/** Optional agent that produces a candidate each cycle. */
|
|
32
|
+
attemptHash?: string;
|
|
33
|
+
/** Configuration for the attempt agent instance. */
|
|
34
|
+
attemptConfig?: Record<string, unknown>;
|
|
35
|
+
/** Instruction used when the built-in attempt step generates a candidate. */
|
|
36
|
+
attemptSystemPrompt?: string;
|
|
37
|
+
/** Maximum number of attempt/score/improve cycles. */
|
|
38
|
+
maxCycles: number;
|
|
39
|
+
/** LLM provider for the built-in attempt step. */
|
|
40
|
+
provider?: string;
|
|
41
|
+
/** LLM model for the built-in attempt step. */
|
|
42
|
+
model?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The precompiled goal controller. Configured (not authored) by `createGoalAgent`.
|
|
46
|
+
*
|
|
47
|
+
* It validates its own contract (so it cannot be tricked into reporting success
|
|
48
|
+
* for an empty or malformed criteria set, even when invoked directly), freezes
|
|
49
|
+
* one candidate per cycle, scores every criterion against that frozen candidate
|
|
50
|
+
* via its pinned scorer, and interprets the results against each criterion's
|
|
51
|
+
* threshold. It completes on the first cycle where all required criteria pass;
|
|
52
|
+
* otherwise it feeds concise unmet-criterion feedback into the next attempt, and
|
|
53
|
+
* reports `unsatisfied` when the cycle limit is reached.
|
|
54
|
+
*/
|
|
55
|
+
export declare const GoalAgentLogic: import("@alveus-ai/core").Agent<{}, GoalAgentLogicInput, ExecutionContext, any>;
|
|
56
|
+
/** An agent reference usable as a scorer or attempt: an agent, virtual agent, or hash. */
|
|
57
|
+
type AgentRef = {
|
|
58
|
+
definition: {
|
|
59
|
+
hash: string;
|
|
60
|
+
};
|
|
61
|
+
} | VirtualAgent | string;
|
|
62
|
+
/** A completion criterion with an optional per-criterion scorer and reference. */
|
|
63
|
+
export interface GoalCriterionSpec extends GoalCriterion {
|
|
64
|
+
/** Scorer for this criterion. Falls back to the goal's default `scorer`. */
|
|
65
|
+
scorer?: AgentRef;
|
|
66
|
+
/** Extra configuration for this criterion's scorer instance. */
|
|
67
|
+
scorerConfig?: Record<string, unknown>;
|
|
68
|
+
/** Expected/reference value, for reference-based criteria. */
|
|
69
|
+
reference?: unknown;
|
|
70
|
+
}
|
|
71
|
+
/** Options for {@link createGoalAgent}. */
|
|
72
|
+
export interface GoalAgentOptions {
|
|
73
|
+
/** At least one uniquely-identified completion criterion. */
|
|
74
|
+
criteria: GoalCriterionSpec[];
|
|
75
|
+
/** Default scorer for criteria that do not name their own. */
|
|
76
|
+
scorer?: AgentRef;
|
|
77
|
+
/** Default scorer configuration. */
|
|
78
|
+
scorerConfig?: Record<string, unknown>;
|
|
79
|
+
/** Optional agent that produces a candidate each cycle. */
|
|
80
|
+
attempt?: AgentRef;
|
|
81
|
+
/** Instruction for the built-in attempt step (when `attempt` is omitted). */
|
|
82
|
+
attemptSystemPrompt?: string;
|
|
83
|
+
/** Maximum attempt/score/improve cycles. Defaults to 4. */
|
|
84
|
+
maxCycles?: number;
|
|
85
|
+
/** LLM provider for the built-in attempt step. */
|
|
86
|
+
provider?: string;
|
|
87
|
+
/** LLM model for the built-in attempt step. */
|
|
88
|
+
model?: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Create a goal agent: a bounded, self-verifying agent that runs until its
|
|
92
|
+
* pinned scorers confirm every criterion passes, or a cycle limit is reached.
|
|
93
|
+
*
|
|
94
|
+
* The objective is supplied at run time; criteria, scorers, and bounds are fixed
|
|
95
|
+
* here. Every terminal run yields a platform-served Completion Receipt (the
|
|
96
|
+
* authoritative outcome).
|
|
97
|
+
*
|
|
98
|
+
* Deploy it by composing it inside an exported agent, so the platform can
|
|
99
|
+
* recognize and attest the goal run:
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* const scorer = agent$(async (_s, { subject }, ctx) => ({
|
|
104
|
+
* results: [{ criterionId: 'valid_json', verdict: isJson(subject), method: 'deterministic' }],
|
|
105
|
+
* }));
|
|
106
|
+
*
|
|
107
|
+
* const goal = createGoalAgent({ criteria: [{ id: 'valid_json' }], scorer, maxCycles: 4 });
|
|
108
|
+
*
|
|
109
|
+
* export const extract = agent$((_s, input, ctx) => ctx.call(goal, input));
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare function createGoalAgent(options: GoalAgentOptions): VirtualAgent<GoalAgentInput, GoalAgentResult>;
|
|
113
|
+
export {};
|
|
114
|
+
//# sourceMappingURL=goal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goal.d.ts","sourceRoot":"","sources":["../../src/agents/goal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,aAAa,EACb,kBAAkB,EAIlB,YAAY,EACb,MAAM,iBAAiB,CAAC;AAEzB,qEAAqE;AACrE,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B,gEAAgE;IAChE,UAAU,EAAE,MAAM,CAAC;IACnB,yEAAyE;IACzE,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,8DAA8D;IAC9D,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAoB,SAAQ,cAAc;IACzD,QAAQ,EAAE,mBAAmB,EAAE,CAAC;IAChC,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oDAAoD;IACpD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,6EAA6E;IAC7E,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB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B,YAAY,EAAE,WAAW,CAAC,QAAQ,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC,YAAY,CAAC;YACxE,SAAS,EAAE,CAAC,CAAC,SAAS;SACvB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,SAAS,IAAI,CAAC,CAAC;IAC7B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,eAAe,GAAG,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAElE,MAAM,YAAY,GAAiC;QACjD,QAAQ,EAAE,UAAU;QACpB,WAAW,EAAE,eAAe,EAAE,IAAI;QAClC,aAAa,EAAE,eAAe,EAAE,MAAM;QACtC,mBAAmB;QACnB,SAAS,EAAE,KAAK;QAChB,QAAQ;QACR,KAAK;KACN,CAAC;IAEF,OAAO;QACL,UAAU,EAAE,cAAc;QAC1B,YAAY,EAAE,YAAuC;KACtD,CAAC;AACJ,CAAC"}
|
package/dist/agents/index.d.ts
CHANGED
|
@@ -5,4 +5,5 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { createChatAgent, createJsonChatAgent, type ChatInput, type ChatOutput, type ChatAgentOptions, } from './basic-chat.js';
|
|
7
7
|
export { ReActLogic, createReActAgent, availableTools, type ReActInput, type ReActOutput, type ReActStep, type ReActAgentOptions, type ToolDefinition, } from './react.js';
|
|
8
|
+
export { GoalAgentLogic, createGoalAgent, type GoalAgentOptions, type GoalCriterionSpec, type GoalAgentLogicInput, type NormalizedCriterion, } from './goal.js';
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAEL,UAAU,EAEV,gBAAgB,EAEhB,cAAc,EAEd,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,cAAc,GACpB,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAEL,UAAU,EAEV,gBAAgB,EAEhB,cAAc,EAEd,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,cAAc,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAEL,cAAc,EAEd,eAAe,EAEf,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,GACzB,MAAM,WAAW,CAAC"}
|
package/dist/agents/index.js
CHANGED
|
@@ -11,4 +11,9 @@ ReActLogic,
|
|
|
11
11
|
createReActAgent,
|
|
12
12
|
// Available tools list
|
|
13
13
|
availableTools, } from './react.js';
|
|
14
|
+
export {
|
|
15
|
+
// The master logic (compiled controller)
|
|
16
|
+
GoalAgentLogic,
|
|
17
|
+
// The factory (returns VirtualAgent)
|
|
18
|
+
createGoalAgent, } from './goal.js';
|
|
14
19
|
//# sourceMappingURL=index.js.map
|
package/dist/agents/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,eAAe,EACf,mBAAmB,GAIpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO;AACL,oCAAoC;AACpC,UAAU;AACV,qCAAqC;AACrC,gBAAgB;AAChB,uBAAuB;AACvB,cAAc,GAOf,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,eAAe,EACf,mBAAmB,GAIpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO;AACL,oCAAoC;AACpC,UAAU;AACV,qCAAqC;AACrC,gBAAgB;AAChB,uBAAuB;AACvB,cAAc,GAOf,MAAM,YAAY,CAAC;AAEpB,OAAO;AACL,yCAAyC;AACzC,cAAc;AACd,qCAAqC;AACrC,eAAe,GAMhB,MAAM,WAAW,CAAC"}
|
package/dist/agents/react.js
CHANGED
|
@@ -349,7 +349,7 @@ Rules:
|
|
|
349
349
|
steps,
|
|
350
350
|
iterations,
|
|
351
351
|
};
|
|
352
|
-
}, { name: 'ReActLogic', hash: "
|
|
352
|
+
}, { name: 'ReActLogic', hash: "fd2d75bca62956931b98463149236799bdf6f09ee9321240c9df7cf2eccbbea4" });
|
|
353
353
|
/**
|
|
354
354
|
* Built-in tool Zod schemas
|
|
355
355
|
*/
|
|
@@ -22,6 +22,7 @@ __export(virtual_agent_exports, {
|
|
|
22
22
|
default: () => virtual_agent_default
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(virtual_agent_exports);
|
|
25
|
+
var import_core = require("@alveus-ai/core");
|
|
25
26
|
var __alveusHandler = async (_state, event, ctx) => {
|
|
26
27
|
const messages = [
|
|
27
28
|
{ role: "system", content: systemPrompt }
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/agents/virtual-agent.ts
|
|
20
|
+
var virtual_agent_exports = {};
|
|
21
|
+
__export(virtual_agent_exports, {
|
|
22
|
+
default: () => virtual_agent_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(virtual_agent_exports);
|
|
25
|
+
var METHODS = /* @__PURE__ */ new Set(["deterministic", "model_assessed", "opaque"]);
|
|
26
|
+
var __alveusHandler = async (_state, event, ctx) => {
|
|
27
|
+
const {
|
|
28
|
+
objective,
|
|
29
|
+
context,
|
|
30
|
+
criteria,
|
|
31
|
+
attemptHash,
|
|
32
|
+
attemptConfig,
|
|
33
|
+
attemptSystemPrompt,
|
|
34
|
+
provider,
|
|
35
|
+
model
|
|
36
|
+
} = event;
|
|
37
|
+
const maxCycles = event.maxCycles;
|
|
38
|
+
if (typeof objective !== "string" || objective.length === 0) {
|
|
39
|
+
throw new Error("Goal contract invalid: objective must be a non-empty string");
|
|
40
|
+
}
|
|
41
|
+
if (!Array.isArray(criteria) || criteria.length === 0) {
|
|
42
|
+
throw new Error("Goal contract invalid: at least one criterion is required");
|
|
43
|
+
}
|
|
44
|
+
if (!Number.isInteger(maxCycles) || maxCycles < 1) {
|
|
45
|
+
throw new Error("Goal contract invalid: maxCycles must be a positive integer");
|
|
46
|
+
}
|
|
47
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
48
|
+
for (const c of criteria) {
|
|
49
|
+
if (!c || typeof c.id !== "string" || c.id.length === 0) {
|
|
50
|
+
throw new Error("Goal contract invalid: every criterion needs a non-empty id");
|
|
51
|
+
}
|
|
52
|
+
if (seenIds.has(c.id)) {
|
|
53
|
+
throw new Error(`Goal contract invalid: duplicate criterion id "${c.id}"`);
|
|
54
|
+
}
|
|
55
|
+
seenIds.add(c.id);
|
|
56
|
+
if (typeof c.scorerHash !== "string" || c.scorerHash.length === 0) {
|
|
57
|
+
throw new Error(`Goal contract invalid: criterion "${c.id}" has no pinned scorer`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const passes = (threshold, r, id) => {
|
|
61
|
+
const t = threshold ?? { kind: "verdict" };
|
|
62
|
+
if (t.kind === "verdict") {
|
|
63
|
+
if (typeof r.verdict !== "boolean") {
|
|
64
|
+
throw new Error(`Scorer did not return a boolean verdict for "${id}"`);
|
|
65
|
+
}
|
|
66
|
+
return r.verdict === true;
|
|
67
|
+
}
|
|
68
|
+
if (t.kind === "minScore") {
|
|
69
|
+
if (typeof r.score !== "number" || !Number.isFinite(r.score)) {
|
|
70
|
+
throw new Error(`Scorer did not return a numeric score for "${id}"`);
|
|
71
|
+
}
|
|
72
|
+
return r.score >= t.min;
|
|
73
|
+
}
|
|
74
|
+
throw new Error(`Unknown threshold kind for "${id}"`);
|
|
75
|
+
};
|
|
76
|
+
const parseScores = (raw, expected) => {
|
|
77
|
+
if (!raw || typeof raw !== "object" || !Array.isArray(raw.results)) {
|
|
78
|
+
throw new Error("Scorer output invalid: missing results array");
|
|
79
|
+
}
|
|
80
|
+
const expectedSet = new Set(expected);
|
|
81
|
+
const byId = /* @__PURE__ */ new Map();
|
|
82
|
+
for (const entry of raw.results) {
|
|
83
|
+
if (!entry || typeof entry !== "object") {
|
|
84
|
+
throw new Error("Scorer output invalid: non-object result entry");
|
|
85
|
+
}
|
|
86
|
+
const { criterionId, method, verdict, score, label, reasoning, metadata, ...extra } = entry;
|
|
87
|
+
if (typeof criterionId !== "string") {
|
|
88
|
+
throw new Error("Scorer output invalid: result missing string criterionId");
|
|
89
|
+
}
|
|
90
|
+
if (!expectedSet.has(criterionId)) {
|
|
91
|
+
throw new Error(`Scorer output invalid: unexpected criterionId "${criterionId}"`);
|
|
92
|
+
}
|
|
93
|
+
if (byId.has(criterionId)) {
|
|
94
|
+
throw new Error(`Scorer output invalid: duplicate result for "${criterionId}"`);
|
|
95
|
+
}
|
|
96
|
+
const extraKeys = Object.keys(extra);
|
|
97
|
+
if (extraKeys.length > 0) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`Scorer output invalid: unknown field(s) for "${criterionId}": ${extraKeys.join(", ")}`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
if (verdict !== void 0 && typeof verdict !== "boolean") {
|
|
103
|
+
throw new Error(`Scorer output invalid: "${criterionId}" verdict must be boolean`);
|
|
104
|
+
}
|
|
105
|
+
if (score !== void 0 && (typeof score !== "number" || !Number.isFinite(score))) {
|
|
106
|
+
throw new Error(`Scorer output invalid: "${criterionId}" score must be a finite number`);
|
|
107
|
+
}
|
|
108
|
+
if (label !== void 0 && typeof label !== "string") {
|
|
109
|
+
throw new Error(`Scorer output invalid: "${criterionId}" label must be a string`);
|
|
110
|
+
}
|
|
111
|
+
if (reasoning !== void 0 && typeof reasoning !== "string") {
|
|
112
|
+
throw new Error(`Scorer output invalid: "${criterionId}" reasoning must be a string`);
|
|
113
|
+
}
|
|
114
|
+
if (method !== void 0 && !METHODS.has(method)) {
|
|
115
|
+
throw new Error(`Scorer output invalid: "${criterionId}" has an unknown method`);
|
|
116
|
+
}
|
|
117
|
+
byId.set(criterionId, {
|
|
118
|
+
result: { verdict, score, label, reasoning, metadata },
|
|
119
|
+
method: method ?? "opaque"
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
for (const id of expected) {
|
|
123
|
+
if (!byId.has(id)) {
|
|
124
|
+
throw new Error(`Scorer output invalid: missing result for "${id}"`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return byId;
|
|
128
|
+
};
|
|
129
|
+
const attempt = async (feedback2) => {
|
|
130
|
+
if (attemptHash) {
|
|
131
|
+
const input = {
|
|
132
|
+
...attemptConfig ?? {},
|
|
133
|
+
objective,
|
|
134
|
+
context,
|
|
135
|
+
feedback: feedback2
|
|
136
|
+
};
|
|
137
|
+
const result = await ctx.call(attemptHash, input);
|
|
138
|
+
return typeof result === "string" ? result : JSON.stringify(result);
|
|
139
|
+
}
|
|
140
|
+
const feedbackText = feedback2.length ? `
|
|
141
|
+
|
|
142
|
+
Your previous attempt did not satisfy:
|
|
143
|
+
${feedback2.join("\n")}
|
|
144
|
+
|
|
145
|
+
Produce an improved result.` : "";
|
|
146
|
+
const contextText = context ? `
|
|
147
|
+
|
|
148
|
+
Context: ${JSON.stringify(context)}` : "";
|
|
149
|
+
const reply = await ctx.llm.chat(
|
|
150
|
+
[
|
|
151
|
+
{
|
|
152
|
+
role: "system",
|
|
153
|
+
content: attemptSystemPrompt ?? "Accomplish the objective. Respond with only the result, no commentary."
|
|
154
|
+
},
|
|
155
|
+
{ role: "user", content: `Objective: ${objective}${contextText}${feedbackText}` }
|
|
156
|
+
],
|
|
157
|
+
{ provider, model }
|
|
158
|
+
);
|
|
159
|
+
return typeof reply === "string" ? reply : reply.content || "";
|
|
160
|
+
};
|
|
161
|
+
const buildGroups = () => {
|
|
162
|
+
const groups2 = /* @__PURE__ */ new Map();
|
|
163
|
+
for (const c of criteria) {
|
|
164
|
+
const key = `${c.scorerHash}\0${JSON.stringify(c.scorerConfig ?? null)}\0${JSON.stringify(c.reference ?? null)}`;
|
|
165
|
+
let g = groups2.get(key);
|
|
166
|
+
if (!g) {
|
|
167
|
+
g = {
|
|
168
|
+
scorerHash: c.scorerHash,
|
|
169
|
+
scorerConfig: c.scorerConfig,
|
|
170
|
+
reference: c.reference,
|
|
171
|
+
ids: []
|
|
172
|
+
};
|
|
173
|
+
groups2.set(key, g);
|
|
174
|
+
}
|
|
175
|
+
g.ids.push(c.id);
|
|
176
|
+
}
|
|
177
|
+
return [...groups2.values()];
|
|
178
|
+
};
|
|
179
|
+
const groups = buildGroups();
|
|
180
|
+
ctx.logger.info("Goal run started", {
|
|
181
|
+
criteria: criteria.map((c) => c.id),
|
|
182
|
+
scorerCount: groups.length,
|
|
183
|
+
maxCycles
|
|
184
|
+
});
|
|
185
|
+
let candidate = "";
|
|
186
|
+
let feedback = [];
|
|
187
|
+
for (let cycle = 1; cycle <= maxCycles; cycle++) {
|
|
188
|
+
candidate = await attempt(feedback);
|
|
189
|
+
await ctx.setState(`goal.cycle.${cycle}.candidate`, candidate);
|
|
190
|
+
const results = /* @__PURE__ */ new Map();
|
|
191
|
+
for (const g of groups) {
|
|
192
|
+
const scorerInput = {
|
|
193
|
+
subject: candidate,
|
|
194
|
+
criteria: g.ids.map((criterionId) => ({ criterionId })),
|
|
195
|
+
reference: g.reference,
|
|
196
|
+
config: g.scorerConfig
|
|
197
|
+
};
|
|
198
|
+
const raw = await ctx.call(g.scorerHash, scorerInput);
|
|
199
|
+
const parsed = parseScores(raw, g.ids);
|
|
200
|
+
for (const [id, v] of parsed) results.set(id, v);
|
|
201
|
+
}
|
|
202
|
+
const evaluated = criteria.map((c) => {
|
|
203
|
+
const scored = results.get(c.id);
|
|
204
|
+
return {
|
|
205
|
+
id: c.id,
|
|
206
|
+
passed: passes(c.threshold, scored.result, c.id),
|
|
207
|
+
reasoning: scored.result.reasoning
|
|
208
|
+
};
|
|
209
|
+
});
|
|
210
|
+
const allPass = evaluated.every((e) => e.passed);
|
|
211
|
+
ctx.logger.info("Goal cycle evaluated", {
|
|
212
|
+
cycle,
|
|
213
|
+
results: evaluated.map((e) => ({ id: e.id, passed: e.passed }))
|
|
214
|
+
});
|
|
215
|
+
await ctx.setState("goal.progress", {
|
|
216
|
+
cycle,
|
|
217
|
+
passed: evaluated.filter((e) => e.passed).map((e) => e.id)
|
|
218
|
+
});
|
|
219
|
+
if (allPass) {
|
|
220
|
+
ctx.logger.info("Goal satisfied", { cycle });
|
|
221
|
+
return { candidate, selfReportedOutcome: "satisfied", finalCycle: cycle };
|
|
222
|
+
}
|
|
223
|
+
feedback = evaluated.filter((e) => !e.passed).map((e) => `- Criterion "${e.id}" not met.${e.reasoning ? ` ${e.reasoning}` : ""}`);
|
|
224
|
+
}
|
|
225
|
+
ctx.logger.info("Goal not satisfied within limit", { maxCycles });
|
|
226
|
+
return { candidate, selfReportedOutcome: "unsatisfied", finalCycle: maxCycles };
|
|
227
|
+
};
|
|
228
|
+
var virtual_agent_default = __alveusHandler;
|
|
@@ -22,6 +22,7 @@ __export(virtual_agent_exports, {
|
|
|
22
22
|
default: () => virtual_agent_default
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(virtual_agent_exports);
|
|
25
|
+
var import_zod2 = require("zod");
|
|
25
26
|
|
|
26
27
|
// src/utils/parse-json.ts
|
|
27
28
|
function parseJsonResponse(text) {
|
|
@@ -93,6 +94,13 @@ function findFirstJsonStart(text) {
|
|
|
93
94
|
return -1;
|
|
94
95
|
}
|
|
95
96
|
|
|
97
|
+
// src/utils/schema.ts
|
|
98
|
+
var import_zod = require("zod");
|
|
99
|
+
function getPromptSchemaString(schema) {
|
|
100
|
+
const jsonSchemaObj = import_zod.z.toJSONSchema(schema);
|
|
101
|
+
return JSON.stringify(jsonSchemaObj, null, 2);
|
|
102
|
+
}
|
|
103
|
+
|
|
96
104
|
// src/utils/json-validator.ts
|
|
97
105
|
function validateJsonSchema(value, schema) {
|
|
98
106
|
const effectiveSchema = schema.properties ? schema : schema;
|
|
@@ -166,6 +174,30 @@ function validateType(value, schema) {
|
|
|
166
174
|
}
|
|
167
175
|
|
|
168
176
|
// src/agents/virtual-agent.ts
|
|
177
|
+
var BUILTIN_SCHEMAS = {
|
|
178
|
+
calculator: import_zod2.z.object({
|
|
179
|
+
expression: import_zod2.z.string().describe("Arithmetic expression to evaluate")
|
|
180
|
+
}),
|
|
181
|
+
string: import_zod2.z.object({
|
|
182
|
+
operation: import_zod2.z.enum(["length", "uppercase", "lowercase", "reverse"]).describe("String operation"),
|
|
183
|
+
text: import_zod2.z.string().describe("Input text")
|
|
184
|
+
})
|
|
185
|
+
};
|
|
186
|
+
var BUILTIN_TOOLS = {
|
|
187
|
+
calculator: {
|
|
188
|
+
hash: "builtin:calculator",
|
|
189
|
+
description: "Performs arithmetic calculations. Supports +, -, *, /, and parentheses.",
|
|
190
|
+
parameters: getPromptSchemaString(BUILTIN_SCHEMAS.calculator),
|
|
191
|
+
jsonSchema: JSON.parse(getPromptSchemaString(BUILTIN_SCHEMAS.calculator))
|
|
192
|
+
},
|
|
193
|
+
string: {
|
|
194
|
+
hash: "builtin:string",
|
|
195
|
+
description: "Performs string operations: length, uppercase, lowercase, reverse",
|
|
196
|
+
parameters: getPromptSchemaString(BUILTIN_SCHEMAS.string),
|
|
197
|
+
jsonSchema: JSON.parse(getPromptSchemaString(BUILTIN_SCHEMAS.string))
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
var availableTools = Object.keys(BUILTIN_TOOLS);
|
|
169
201
|
var __alveusHandler = async (_state, event, ctx) => {
|
|
170
202
|
const BUILTIN_EXECUTORS = {
|
|
171
203
|
"builtin:calculator": async ({ expression }) => {
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Goal Agent Example
|
|
3
|
+
*
|
|
4
|
+
* A bounded, self-verifying agent: it attempts an objective and scores the
|
|
5
|
+
* result against explicit criteria using a pinned scorer, looping until every
|
|
6
|
+
* criterion passes or a cycle limit is reached. Every terminal run yields a
|
|
7
|
+
* platform-served Completion Receipt (the authoritative outcome) that the agent
|
|
8
|
+
* itself cannot forge.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* alveus deploy
|
|
12
|
+
* alveus run @yourscope/goal-agent --input '{"objective": "extract the cert as JSON"}'
|
|
13
|
+
* alveus receipt <execution-id>
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { agent$ } from '@alveus-ai/core';
|
|
17
|
+
import type { ExecutionContext, ScorerInput, ScorerOutput } from '@alveus-ai/core';
|
|
18
|
+
import { createGoalAgent } from '@alveus-ai/std';
|
|
19
|
+
|
|
20
|
+
interface AttemptInput {
|
|
21
|
+
objective: string;
|
|
22
|
+
feedback?: string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Attempt step: produces a candidate. This demo is deterministic — it emits an
|
|
27
|
+
* incomplete result first, then a complete one once it receives feedback — so
|
|
28
|
+
* the self-correction loop is easy to observe.
|
|
29
|
+
*/
|
|
30
|
+
const attempt = agent$(async (_state, input: AttemptInput, _ctx: ExecutionContext) => {
|
|
31
|
+
const improved = (input.feedback?.length ?? 0) > 0;
|
|
32
|
+
return improved
|
|
33
|
+
? JSON.stringify({ certification: 'SOC 2 Type II', evidence: ['soc2_report.pdf'] })
|
|
34
|
+
: JSON.stringify({ note: 'still gathering details' });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Scorer: a deterministic check over the candidate. It only measures — it
|
|
39
|
+
* returns a verdict per criterion and never decides completion.
|
|
40
|
+
*/
|
|
41
|
+
const certScorer = agent$(async (_state, input: ScorerInput, _ctx: ExecutionContext) => {
|
|
42
|
+
let parsed: Record<string, unknown> | null = null;
|
|
43
|
+
try {
|
|
44
|
+
parsed = JSON.parse(String(input.subject));
|
|
45
|
+
} catch {
|
|
46
|
+
parsed = null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const check = (id: string): boolean => {
|
|
50
|
+
if (id === 'valid_json') return parsed !== null;
|
|
51
|
+
if (id === 'cert_named') return typeof parsed?.certification === 'string';
|
|
52
|
+
if (id === 'has_evidence') return Array.isArray(parsed?.evidence) && parsed.evidence.length > 0;
|
|
53
|
+
return false;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const output: ScorerOutput = {
|
|
57
|
+
results: input.criteria.map((c) => ({
|
|
58
|
+
criterionId: c.criterionId,
|
|
59
|
+
verdict: check(c.criterionId),
|
|
60
|
+
method: 'deterministic',
|
|
61
|
+
})),
|
|
62
|
+
};
|
|
63
|
+
return output;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const goal = createGoalAgent({
|
|
67
|
+
criteria: [{ id: 'valid_json' }, { id: 'cert_named' }, { id: 'has_evidence' }],
|
|
68
|
+
scorer: certScorer,
|
|
69
|
+
attempt,
|
|
70
|
+
maxCycles: 3,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Deployable root: compose the goal agent so the platform can recognize and
|
|
75
|
+
* attest the run. The receipt is retrieved separately, from the platform.
|
|
76
|
+
*/
|
|
77
|
+
export const goalAgent = agent$((_state, input: { objective: string }, ctx: ExecutionContext) =>
|
|
78
|
+
ctx.call(goal, input),
|
|
79
|
+
);
|