rax-flow-agents 0.1.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.
@@ -0,0 +1,3 @@
1
+ export * from "./schemas.js";
2
+ export * from "./official-agents.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./schemas.js";
2
+ export * from "./official-agents.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { AgentDefinition, IModelProvider } from "@rax-flow/core";
2
+ interface RuntimeOptions {
3
+ providers: Record<string, IModelProvider>;
4
+ defaultProvider?: string;
5
+ strongProvider?: string;
6
+ providerModels?: Record<string, string>;
7
+ }
8
+ export declare function buildOfficialAgents(): Record<string, AgentDefinition>;
9
+ export declare function buildOfficialAgentsRuntime(options: RuntimeOptions): Record<string, AgentDefinition>;
10
+ export declare function listOfficialAgents(): readonly [{
11
+ readonly name: "IntentClassifierAgent";
12
+ readonly role: "Classify user intent and pick workflow";
13
+ readonly activationWhen: "Always first";
14
+ }, {
15
+ readonly name: "BrainstormAgent";
16
+ readonly role: "Generate diverse solution paths";
17
+ readonly activationWhen: "Idea exploration requested";
18
+ }, {
19
+ readonly name: "SpecAgent";
20
+ readonly role: "Write actionable specification";
21
+ readonly activationWhen: "Requirements are vague";
22
+ }, {
23
+ readonly name: "ArchitectureAgent";
24
+ readonly role: "Design scalable architecture";
25
+ readonly activationWhen: "System design requested";
26
+ }, {
27
+ readonly name: "TaskPlannerAgent";
28
+ readonly role: "Break work into executable tasks";
29
+ readonly activationWhen: "Execution planning phase";
30
+ }, {
31
+ readonly name: "CodeGeneratorAgent";
32
+ readonly role: "Generate implementation artifacts";
33
+ readonly activationWhen: "Code delivery required";
34
+ }, {
35
+ readonly name: "TestAgent";
36
+ readonly role: "Generate and run test strategy";
37
+ readonly activationWhen: "Validation phase";
38
+ }, {
39
+ readonly name: "ValidatorAgent";
40
+ readonly role: "Validate output schemas and constraints";
41
+ readonly activationWhen: "After each major step";
42
+ }, {
43
+ readonly name: "FixAgent";
44
+ readonly role: "Patch detected defects";
45
+ readonly activationWhen: "Verify fails";
46
+ }, {
47
+ readonly name: "OptimizerAgent";
48
+ readonly role: "Reduce latency/cost and improve quality";
49
+ readonly activationWhen: "Performance optimization needed";
50
+ }, {
51
+ readonly name: "DocumentationAgent";
52
+ readonly role: "Generate technical/user docs";
53
+ readonly activationWhen: "Delivery finalization";
54
+ }, {
55
+ readonly name: "BenchmarkAgent";
56
+ readonly role: "Measure quality/cost/latency deltas";
57
+ readonly activationWhen: "Benchmark mode enabled";
58
+ }];
59
+ export {};
60
+ //# sourceMappingURL=official-agents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"official-agents.d.ts","sourceRoot":"","sources":["../src/official-agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA2B,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAgC1F,UAAU,cAAc;IACtB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC1C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AA2DD,wBAAgB,mBAAmB,IAAI,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAcrE;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAcnG;AAED,wBAAgB,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAEjC"}
@@ -0,0 +1,113 @@
1
+ import { agentInputSchema, agentOutputSchema } from "./schemas.js";
2
+ const officialAgents = [
3
+ { name: "IntentClassifierAgent", role: "Classify user intent and pick workflow", activationWhen: "Always first" },
4
+ { name: "BrainstormAgent", role: "Generate diverse solution paths", activationWhen: "Idea exploration requested" },
5
+ { name: "SpecAgent", role: "Write actionable specification", activationWhen: "Requirements are vague" },
6
+ { name: "ArchitectureAgent", role: "Design scalable architecture", activationWhen: "System design requested" },
7
+ { name: "TaskPlannerAgent", role: "Break work into executable tasks", activationWhen: "Execution planning phase" },
8
+ { name: "CodeGeneratorAgent", role: "Generate implementation artifacts", activationWhen: "Code delivery required" },
9
+ { name: "TestAgent", role: "Generate and run test strategy", activationWhen: "Validation phase" },
10
+ { name: "ValidatorAgent", role: "Validate output schemas and constraints", activationWhen: "After each major step" },
11
+ { name: "FixAgent", role: "Patch detected defects", activationWhen: "Verify fails" },
12
+ { name: "OptimizerAgent", role: "Reduce latency/cost and improve quality", activationWhen: "Performance optimization needed" },
13
+ { name: "DocumentationAgent", role: "Generate technical/user docs", activationWhen: "Delivery finalization" },
14
+ { name: "BenchmarkAgent", role: "Measure quality/cost/latency deltas", activationWhen: "Benchmark mode enabled" }
15
+ ];
16
+ function deterministicRun(name, role) {
17
+ return async (input) => ({
18
+ agent: name,
19
+ success: true,
20
+ confidence: 0.8,
21
+ risks: [],
22
+ logs: [`${name} executed`, `Role: ${role}`],
23
+ data: {
24
+ summary: `${name} processed task ${input.taskId}`,
25
+ nextAction: "continue"
26
+ }
27
+ });
28
+ }
29
+ function pickProvider(options, input) {
30
+ const tier = String(input.context?.modelTier ?? "default");
31
+ const preferred = tier === "strong" ? options.strongProvider : options.defaultProvider;
32
+ if (preferred && options.providers[preferred]) {
33
+ return { name: preferred, provider: options.providers[preferred] };
34
+ }
35
+ const firstEntry = Object.entries(options.providers)[0];
36
+ const first = firstEntry?.[1];
37
+ if (!first) {
38
+ throw new Error("no_provider_available");
39
+ }
40
+ return { name: firstEntry[0], provider: first };
41
+ }
42
+ function runtimeRun(name, role, options) {
43
+ return async (input) => {
44
+ const selected = pickProvider(options, input);
45
+ const model = options.providerModels?.[selected.name];
46
+ const prompt = [
47
+ `You are ${name}.`,
48
+ `Role: ${role}.`,
49
+ "Return STRICT JSON matching the required schema.",
50
+ `Task: ${input.userPrompt}`,
51
+ `TaskId: ${input.taskId}`,
52
+ `Context: ${JSON.stringify(input.context ?? {})}`,
53
+ `Artifacts: ${JSON.stringify(input.artifacts ?? {})}`,
54
+ "Keep output concise and actionable."
55
+ ].join("\n");
56
+ try {
57
+ const response = await selected.provider.callStructured(prompt, agentOutputSchema, {
58
+ temperature: 0,
59
+ maxTokens: 1400,
60
+ model
61
+ });
62
+ return {
63
+ ...response.output,
64
+ logs: [...(response.output.logs ?? []), `${name} provider=${response.provider} model=${response.model}`],
65
+ usage: response.usage,
66
+ costUsd: response.costUsd
67
+ };
68
+ }
69
+ catch (error) {
70
+ return {
71
+ agent: name,
72
+ success: false,
73
+ confidence: 0.35,
74
+ risks: ["latency"],
75
+ logs: [`provider_call_failed:${String(error)}`],
76
+ data: {
77
+ summary: `${name} failed to produce structured output`,
78
+ nextAction: "retry"
79
+ }
80
+ };
81
+ }
82
+ };
83
+ }
84
+ export function buildOfficialAgents() {
85
+ return Object.fromEntries(officialAgents.map((agent) => [
86
+ agent.name,
87
+ {
88
+ name: agent.name,
89
+ role: agent.role,
90
+ activationWhen: agent.activationWhen,
91
+ inputSchema: agentInputSchema,
92
+ outputSchema: agentOutputSchema,
93
+ run: deterministicRun(agent.name, agent.role)
94
+ }
95
+ ]));
96
+ }
97
+ export function buildOfficialAgentsRuntime(options) {
98
+ return Object.fromEntries(officialAgents.map((agent) => [
99
+ agent.name,
100
+ {
101
+ name: agent.name,
102
+ role: agent.role,
103
+ activationWhen: agent.activationWhen,
104
+ inputSchema: agentInputSchema,
105
+ outputSchema: agentOutputSchema,
106
+ run: runtimeRun(agent.name, agent.role, options)
107
+ }
108
+ ]));
109
+ }
110
+ export function listOfficialAgents() {
111
+ return officialAgents;
112
+ }
113
+ //# sourceMappingURL=official-agents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"official-agents.js","sourceRoot":"","sources":["../src/official-agents.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEnE,MAAM,cAAc,GAAG;IACrB,EAAE,IAAI,EAAE,uBAAuB,EAAE,IAAI,EAAE,wCAAwC,EAAE,cAAc,EAAE,cAAc,EAAE;IACjH,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,iCAAiC,EAAE,cAAc,EAAE,4BAA4B,EAAE;IAClH,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,gCAAgC,EAAE,cAAc,EAAE,wBAAwB,EAAE;IACvG,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,8BAA8B,EAAE,cAAc,EAAE,yBAAyB,EAAE;IAC9G,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,kCAAkC,EAAE,cAAc,EAAE,0BAA0B,EAAE;IAClH,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,mCAAmC,EAAE,cAAc,EAAE,wBAAwB,EAAE;IACnH,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,gCAAgC,EAAE,cAAc,EAAE,kBAAkB,EAAE;IACjG,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,yCAAyC,EAAE,cAAc,EAAE,uBAAuB,EAAE;IACpH,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,wBAAwB,EAAE,cAAc,EAAE,cAAc,EAAE;IACpF,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,yCAAyC,E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AAE,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC;SACvB;KAC5B,CAAC,CACH,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,cAAc,CAAC;AACxB,CAAC"}
@@ -0,0 +1,56 @@
1
+ export declare const agentOutputSchema: {
2
+ readonly type: "object";
3
+ readonly required: readonly ["agent", "success", "confidence", "risks", "logs", "data"];
4
+ readonly additionalProperties: false;
5
+ readonly properties: {
6
+ readonly agent: {
7
+ readonly type: "string";
8
+ };
9
+ readonly success: {
10
+ readonly type: "boolean";
11
+ };
12
+ readonly confidence: {
13
+ readonly type: "number";
14
+ readonly minimum: 0;
15
+ readonly maximum: 1;
16
+ };
17
+ readonly risks: {
18
+ readonly type: "array";
19
+ readonly items: {
20
+ readonly type: "string";
21
+ };
22
+ };
23
+ readonly logs: {
24
+ readonly type: "array";
25
+ readonly items: {
26
+ readonly type: "string";
27
+ };
28
+ };
29
+ readonly data: {
30
+ readonly type: "object";
31
+ readonly additionalProperties: true;
32
+ };
33
+ };
34
+ };
35
+ export declare const agentInputSchema: {
36
+ readonly type: "object";
37
+ readonly required: readonly ["taskId", "userPrompt"];
38
+ readonly additionalProperties: false;
39
+ readonly properties: {
40
+ readonly taskId: {
41
+ readonly type: "string";
42
+ };
43
+ readonly userPrompt: {
44
+ readonly type: "string";
45
+ };
46
+ readonly context: {
47
+ readonly type: "object";
48
+ readonly additionalProperties: true;
49
+ };
50
+ readonly artifacts: {
51
+ readonly type: "object";
52
+ readonly additionalProperties: true;
53
+ };
54
+ };
55
+ };
56
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqBpB,CAAC;AAEX,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;CAUnB,CAAC"}
@@ -0,0 +1,34 @@
1
+ export const agentOutputSchema = {
2
+ type: "object",
3
+ required: ["agent", "success", "confidence", "risks", "logs", "data"],
4
+ additionalProperties: false,
5
+ properties: {
6
+ agent: { type: "string" },
7
+ success: { type: "boolean" },
8
+ confidence: { type: "number", minimum: 0, maximum: 1 },
9
+ risks: {
10
+ type: "array",
11
+ items: { type: "string" }
12
+ },
13
+ logs: {
14
+ type: "array",
15
+ items: { type: "string" }
16
+ },
17
+ data: {
18
+ type: "object",
19
+ additionalProperties: true
20
+ }
21
+ }
22
+ };
23
+ export const agentInputSchema = {
24
+ type: "object",
25
+ required: ["taskId", "userPrompt"],
26
+ additionalProperties: false,
27
+ properties: {
28
+ taskId: { type: "string" },
29
+ userPrompt: { type: "string" },
30
+ context: { type: "object", additionalProperties: true },
31
+ artifacts: { type: "object", additionalProperties: true }
32
+ }
33
+ };
34
+ //# sourceMappingURL=schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC;IACrE,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACzB,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;QAC5B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE;QACtD,KAAK,EAAE;YACL,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC1B;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC1B;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,oBAAoB,EAAE,IAAI;SAC3B;KACF;CACO,CAAC;AAEX,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC;IAClC,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC1B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC9B,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,oBAAoB,EAAE,IAAI,EAAE;QACvD,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,oBAAoB,EAAE,IAAI,EAAE;KAC1D;CACO,CAAC"}
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "rax-flow-agents",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc -p tsconfig.json",
9
+ "test": "vitest run --passWithNoTests",
10
+ "typecheck": "tsc -p tsconfig.json --noEmit"
11
+ },
12
+ "dependencies": {
13
+ "rax-flow-core": "0.1.0"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ }
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./schemas.js";
2
+ export * from "./official-agents.js";
@@ -0,0 +1,131 @@
1
+ import { AgentDefinition, AgentInput, AgentOutput, IModelProvider } from "@rax-flow/core";
2
+ import { agentInputSchema, agentOutputSchema } from "./schemas.js";
3
+
4
+ const officialAgents = [
5
+ { name: "IntentClassifierAgent", role: "Classify user intent and pick workflow", activationWhen: "Always first" },
6
+ { name: "BrainstormAgent", role: "Generate diverse solution paths", activationWhen: "Idea exploration requested" },
7
+ { name: "SpecAgent", role: "Write actionable specification", activationWhen: "Requirements are vague" },
8
+ { name: "ArchitectureAgent", role: "Design scalable architecture", activationWhen: "System design requested" },
9
+ { name: "TaskPlannerAgent", role: "Break work into executable tasks", activationWhen: "Execution planning phase" },
10
+ { name: "CodeGeneratorAgent", role: "Generate implementation artifacts", activationWhen: "Code delivery required" },
11
+ { name: "TestAgent", role: "Generate and run test strategy", activationWhen: "Validation phase" },
12
+ { name: "ValidatorAgent", role: "Validate output schemas and constraints", activationWhen: "After each major step" },
13
+ { name: "FixAgent", role: "Patch detected defects", activationWhen: "Verify fails" },
14
+ { name: "OptimizerAgent", role: "Reduce latency/cost and improve quality", activationWhen: "Performance optimization needed" },
15
+ { name: "DocumentationAgent", role: "Generate technical/user docs", activationWhen: "Delivery finalization" },
16
+ { name: "BenchmarkAgent", role: "Measure quality/cost/latency deltas", activationWhen: "Benchmark mode enabled" }
17
+ ] as const;
18
+
19
+ function deterministicRun(name: string, role: string) {
20
+ return async (input: AgentInput): Promise<AgentOutput> => ({
21
+ agent: name,
22
+ success: true,
23
+ confidence: 0.8,
24
+ risks: [],
25
+ logs: [`${name} executed`, `Role: ${role}`],
26
+ data: {
27
+ summary: `${name} processed task ${input.taskId}`,
28
+ nextAction: "continue"
29
+ }
30
+ });
31
+ }
32
+
33
+ interface RuntimeOptions {
34
+ providers: Record<string, IModelProvider>;
35
+ defaultProvider?: string;
36
+ strongProvider?: string;
37
+ providerModels?: Record<string, string>;
38
+ }
39
+
40
+ function pickProvider(options: RuntimeOptions, input: AgentInput): { name: string; provider: IModelProvider } {
41
+ const tier = String(input.context?.modelTier ?? "default");
42
+ const preferred = tier === "strong" ? options.strongProvider : options.defaultProvider;
43
+ if (preferred && options.providers[preferred]) {
44
+ return { name: preferred, provider: options.providers[preferred] };
45
+ }
46
+ const firstEntry = Object.entries(options.providers)[0];
47
+ const first = firstEntry?.[1];
48
+ if (!first) {
49
+ throw new Error("no_provider_available");
50
+ }
51
+ return { name: firstEntry[0], provider: first };
52
+ }
53
+
54
+ function runtimeRun(name: string, role: string, options: RuntimeOptions) {
55
+ return async (input: AgentInput): Promise<AgentOutput> => {
56
+ const selected = pickProvider(options, input);
57
+ const model = options.providerModels?.[selected.name];
58
+ const prompt = [
59
+ `You are ${name}.`,
60
+ `Role: ${role}.`,
61
+ "Return STRICT JSON matching the required schema.",
62
+ `Task: ${input.userPrompt}`,
63
+ `TaskId: ${input.taskId}`,
64
+ `Context: ${JSON.stringify(input.context ?? {})}`,
65
+ `Artifacts: ${JSON.stringify(input.artifacts ?? {})}`,
66
+ "Keep output concise and actionable."
67
+ ].join("\n");
68
+
69
+ try {
70
+ const response = await selected.provider.callStructured<AgentOutput>(prompt, agentOutputSchema, {
71
+ temperature: 0,
72
+ maxTokens: 1400,
73
+ model
74
+ });
75
+ return {
76
+ ...response.output,
77
+ logs: [...(response.output.logs ?? []), `${name} provider=${response.provider} model=${response.model}`],
78
+ usage: response.usage,
79
+ costUsd: response.costUsd
80
+ };
81
+ } catch (error) {
82
+ return {
83
+ agent: name,
84
+ success: false,
85
+ confidence: 0.35,
86
+ risks: ["latency"],
87
+ logs: [`provider_call_failed:${String(error)}`],
88
+ data: {
89
+ summary: `${name} failed to produce structured output`,
90
+ nextAction: "retry"
91
+ }
92
+ };
93
+ }
94
+ };
95
+ }
96
+
97
+ export function buildOfficialAgents(): Record<string, AgentDefinition> {
98
+ return Object.fromEntries(
99
+ officialAgents.map((agent) => [
100
+ agent.name,
101
+ {
102
+ name: agent.name,
103
+ role: agent.role,
104
+ activationWhen: agent.activationWhen,
105
+ inputSchema: agentInputSchema,
106
+ outputSchema: agentOutputSchema,
107
+ run: deterministicRun(agent.name, agent.role)
108
+ } satisfies AgentDefinition
109
+ ])
110
+ );
111
+ }
112
+
113
+ export function buildOfficialAgentsRuntime(options: RuntimeOptions): Record<string, AgentDefinition> {
114
+ return Object.fromEntries(
115
+ officialAgents.map((agent) => [
116
+ agent.name,
117
+ {
118
+ name: agent.name,
119
+ role: agent.role,
120
+ activationWhen: agent.activationWhen,
121
+ inputSchema: agentInputSchema,
122
+ outputSchema: agentOutputSchema,
123
+ run: runtimeRun(agent.name, agent.role, options)
124
+ } satisfies AgentDefinition
125
+ ])
126
+ );
127
+ }
128
+
129
+ export function listOfficialAgents() {
130
+ return officialAgents;
131
+ }
package/src/schemas.ts ADDED
@@ -0,0 +1,34 @@
1
+ export const agentOutputSchema = {
2
+ type: "object",
3
+ required: ["agent", "success", "confidence", "risks", "logs", "data"],
4
+ additionalProperties: false,
5
+ properties: {
6
+ agent: { type: "string" },
7
+ success: { type: "boolean" },
8
+ confidence: { type: "number", minimum: 0, maximum: 1 },
9
+ risks: {
10
+ type: "array",
11
+ items: { type: "string" }
12
+ },
13
+ logs: {
14
+ type: "array",
15
+ items: { type: "string" }
16
+ },
17
+ data: {
18
+ type: "object",
19
+ additionalProperties: true
20
+ }
21
+ }
22
+ } as const;
23
+
24
+ export const agentInputSchema = {
25
+ type: "object",
26
+ required: ["taskId", "userPrompt"],
27
+ additionalProperties: false,
28
+ properties: {
29
+ taskId: { type: "string" },
30
+ userPrompt: { type: "string" },
31
+ context: { type: "object", additionalProperties: true },
32
+ artifacts: { type: "object", additionalProperties: true }
33
+ }
34
+ } as const;
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "composite": true,
7
+ "declaration": true,
8
+ "declarationMap": true
9
+ },
10
+ "include": [
11
+ "src/**/*.ts"
12
+ ],
13
+ "references": [
14
+ {
15
+ "path": "../core"
16
+ }
17
+ ]
18
+ }