@alveus-ai/std 0.1.53 → 0.1.54
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/examples/goal-agent.ts +9 -9
- package/package.json +1 -1
package/examples/goal-agent.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Usage:
|
|
11
11
|
* alveus deploy
|
|
12
|
-
* alveus run @yourscope/goal-agent --input '{"objective": "extract the
|
|
12
|
+
* alveus run @yourscope/goal-agent --input '{"objective": "extract the contact as JSON"}'
|
|
13
13
|
* alveus receipt <execution-id>
|
|
14
14
|
*/
|
|
15
15
|
|
|
@@ -30,7 +30,7 @@ interface AttemptInput {
|
|
|
30
30
|
const attempt = agent$(async (_state, input: AttemptInput, _ctx: ExecutionContext) => {
|
|
31
31
|
const improved = (input.feedback?.length ?? 0) > 0;
|
|
32
32
|
return improved
|
|
33
|
-
? JSON.stringify({
|
|
33
|
+
? JSON.stringify({ name: 'Ada Lovelace', emails: ['ada@example.com'] })
|
|
34
34
|
: JSON.stringify({ note: 'still gathering details' });
|
|
35
35
|
});
|
|
36
36
|
|
|
@@ -38,7 +38,7 @@ const attempt = agent$(async (_state, input: AttemptInput, _ctx: ExecutionContex
|
|
|
38
38
|
* Scorer: a deterministic check over the candidate. It only measures — it
|
|
39
39
|
* returns a verdict per criterion and never decides completion.
|
|
40
40
|
*/
|
|
41
|
-
const
|
|
41
|
+
const contactScorer = agent$(async (_state, input: ScorerInput, _ctx: ExecutionContext) => {
|
|
42
42
|
let parsed: Record<string, unknown> | null = null;
|
|
43
43
|
try {
|
|
44
44
|
parsed = JSON.parse(String(input.subject));
|
|
@@ -48,8 +48,8 @@ const certScorer = agent$(async (_state, input: ScorerInput, _ctx: ExecutionCont
|
|
|
48
48
|
|
|
49
49
|
const check = (id: string): boolean => {
|
|
50
50
|
if (id === 'valid_json') return parsed !== null;
|
|
51
|
-
if (id === '
|
|
52
|
-
if (id === '
|
|
51
|
+
if (id === 'has_name') return typeof parsed?.name === 'string';
|
|
52
|
+
if (id === 'has_emails') return Array.isArray(parsed?.emails) && parsed.emails.length > 0;
|
|
53
53
|
return false;
|
|
54
54
|
};
|
|
55
55
|
|
|
@@ -64,8 +64,8 @@ const certScorer = agent$(async (_state, input: ScorerInput, _ctx: ExecutionCont
|
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
const goal = createGoalAgent({
|
|
67
|
-
criteria: [{ id: 'valid_json' }, { id: '
|
|
68
|
-
scorer:
|
|
67
|
+
criteria: [{ id: 'valid_json' }, { id: 'has_name' }, { id: 'has_emails' }],
|
|
68
|
+
scorer: contactScorer,
|
|
69
69
|
attempt,
|
|
70
70
|
maxCycles: 3,
|
|
71
71
|
});
|
|
@@ -76,6 +76,6 @@ const goal = createGoalAgent({
|
|
|
76
76
|
*/
|
|
77
77
|
export const goalAgent = agent$((_state, input: { objective: string }, ctx: ExecutionContext) =>
|
|
78
78
|
// Label this run by its objective, so the graph's node reads what it is for
|
|
79
|
-
// ("extract the
|
|
79
|
+
// ("extract the contact as JSON") instead of an anonymous agent hash.
|
|
80
80
|
ctx.call(goal, input, { label: input.objective }),
|
|
81
|
-
);
|
|
81
|
+
);
|