@openliate/liate 0.0.0-stage → 0.1.6

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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +127 -2
  3. package/README.npm.md +128 -0
  4. package/dist/bin.js +28745 -0
  5. package/dist/liate.js +39479 -0
  6. package/dist/runtime/hono.js +28072 -0
  7. package/dist/runtime/index.js +28072 -0
  8. package/hub/agents/docgyan-agent/agent.json +27 -0
  9. package/hub/agents/docgyan-agent/agent.ts +39 -0
  10. package/hub/agents/gnani-agent/agent.json +17 -0
  11. package/hub/agents/neon-agent/agent.json +18 -0
  12. package/hub/agents/prism-agent/agent.json +17 -0
  13. package/hub/agents/sarvam-agent/agent.json +22 -0
  14. package/package.json +71 -4
  15. package/src/cli/index.ts +346 -0
  16. package/src/cli/resolver.ts +153 -0
  17. package/src/core/aum.ts +137 -0
  18. package/src/core/om.ts +159 -0
  19. package/src/core/spec.ts +112 -0
  20. package/src/core/uuid.ts +8 -0
  21. package/src/core/version.ts +2 -0
  22. package/src/layers/agent/harness.ts +118 -0
  23. package/src/layers/agent/loop.ts +203 -0
  24. package/src/layers/agent/skills.ts +302 -0
  25. package/src/layers/agent/types.ts +66 -0
  26. package/src/layers/environment/sandbox.ts +107 -0
  27. package/src/layers/environment/types.ts +23 -0
  28. package/src/layers/integration/knowledge.ts +187 -0
  29. package/src/layers/integration/lib.ts +167 -0
  30. package/src/layers/integration/memory.ts +135 -0
  31. package/src/layers/integration/repo.ts +273 -0
  32. package/src/layers/integration/types.ts +60 -0
  33. package/src/layers/llm/model.ts +928 -0
  34. package/src/layers/llm/types.ts +64 -0
  35. package/src/layers/tools/mcp.ts +236 -0
  36. package/src/layers/tools/registry.ts +307 -0
  37. package/src/layers/tools/server.ts +69 -0
  38. package/src/layers/tools/types.ts +38 -0
  39. package/src/liate.ts +65 -0
  40. package/src/routes/skills.ts +73 -0
  41. package/src/runtime/hono.ts +346 -0
  42. package/src/runtime/wasm.ts +23 -0
  43. package/src/scaffold/project.ts +188 -0
@@ -0,0 +1,153 @@
1
+ // src/cli/resolver.ts
2
+ // Liate CLI Dynamic Agent Resolver & Local Hub
3
+
4
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
5
+ import { resolve, isAbsolute, extname, join } from "node:path";
6
+ import { liate } from "@/core/om";
7
+
8
+ export interface ResolvedAgentTarget {
9
+ agent: liate;
10
+ sourcePath?: string;
11
+ sourceType: "typescript" | "javascript" | "json" | "hub" | "ephemeral";
12
+ }
13
+
14
+ export interface HubAgentSummary {
15
+ id: string;
16
+ name: string;
17
+ model: string;
18
+ intent: string;
19
+ path: string;
20
+ }
21
+
22
+ /**
23
+ * Lists all local agent templates available in hub/agents
24
+ */
25
+ export function listLocalHubAgents(): HubAgentSummary[] {
26
+ const cwd = process.cwd();
27
+ const hubDir = resolve(cwd, "hub", "agents");
28
+
29
+ if (!existsSync(hubDir)) {
30
+ return [];
31
+ }
32
+
33
+ const list: HubAgentSummary[] = [];
34
+ const entries = readdirSync(hubDir, { withFileTypes: true });
35
+
36
+ for (const entry of entries) {
37
+ if (entry.isDirectory()) {
38
+ const agentJsonPath = join(hubDir, entry.name, "agent.json");
39
+ if (existsSync(agentJsonPath)) {
40
+ try {
41
+ const raw = JSON.parse(readFileSync(agentJsonPath, "utf-8"));
42
+ list.push({
43
+ id: entry.name,
44
+ name: raw.A?.name || entry.name,
45
+ model: typeof raw.L === "string" ? raw.L : (raw.L?.model || "sarvam/sarvam-105b"),
46
+ intent: raw.A?.intent || "Autonomous Sovereign Agent",
47
+ path: agentJsonPath
48
+ });
49
+ } catch {
50
+ // Skip invalid json
51
+ }
52
+ }
53
+ }
54
+ }
55
+
56
+ return list;
57
+ }
58
+
59
+ /**
60
+ * Discovers and loads an agent from an explicit file path, local hub, or current directory
61
+ */
62
+ export async function resolveAgent(customTarget?: string): Promise<ResolvedAgentTarget> {
63
+ const cwd = process.cwd();
64
+
65
+ // 1. Explicit path or hub agent name passed by user
66
+ if (customTarget && customTarget.trim().length > 0) {
67
+ let candidatePath = isAbsolute(customTarget) ? customTarget : resolve(cwd, customTarget);
68
+
69
+ // Check if target is a hub agent directory name (e.g. "sarvam-agent" or "prism-agent")
70
+ const hubCandidate = resolve(cwd, "hub", "agents", customTarget, "agent.json");
71
+ if (existsSync(hubCandidate)) {
72
+ const agent = await liate.load(hubCandidate);
73
+ return { agent, sourcePath: hubCandidate, sourceType: "hub" };
74
+ }
75
+
76
+ // Check if candidatePath is a directory containing agent.json
77
+ if (existsSync(candidatePath) && statSync(candidatePath).isDirectory()) {
78
+ const dirJson = join(candidatePath, "agent.json");
79
+ if (existsSync(dirJson)) {
80
+ const agent = await liate.load(dirJson);
81
+ return { agent, sourcePath: dirJson, sourceType: "json" };
82
+ }
83
+ }
84
+
85
+ if (existsSync(candidatePath)) {
86
+ const ext = extname(candidatePath).toLowerCase();
87
+
88
+ if (ext === ".json") {
89
+ const agent = await liate.load(candidatePath);
90
+ return { agent, sourcePath: candidatePath, sourceType: "json" };
91
+ }
92
+
93
+ if (ext === ".ts" || ext === ".js" || ext === ".mjs") {
94
+ const imported = await import(candidatePath);
95
+ const ExportedClass = imported.default || Object.values(imported).find(
96
+ (val: any) => typeof val === "function" && (val.prototype instanceof liate || val === liate)
97
+ );
98
+
99
+ if (ExportedClass && typeof ExportedClass === "function") {
100
+ const instance = new (ExportedClass as any)();
101
+ return { agent: instance, sourcePath: candidatePath, sourceType: ext === ".ts" ? "typescript" : "javascript" };
102
+ }
103
+
104
+ if (imported.default instanceof liate) {
105
+ return { agent: imported.default, sourcePath: candidatePath, sourceType: ext === ".ts" ? "typescript" : "javascript" };
106
+ }
107
+ }
108
+ }
109
+ }
110
+
111
+ // 2. Automatic discovery in current directory: agent.ts -> agent.json -> agent.js
112
+ const tsCandidate = resolve(cwd, "agent.ts");
113
+ if (existsSync(tsCandidate)) {
114
+ try {
115
+ const imported = await import(tsCandidate);
116
+ const ExportedClass = imported.default || Object.values(imported).find(
117
+ (val: any) => typeof val === "function" && (val.prototype instanceof liate || val === liate)
118
+ );
119
+
120
+ if (ExportedClass && typeof ExportedClass === "function") {
121
+ return { agent: new (ExportedClass as any)(), sourcePath: tsCandidate, sourceType: "typescript" };
122
+ }
123
+ } catch {
124
+ // Fall through to json
125
+ }
126
+ }
127
+
128
+ const jsonCandidate = resolve(cwd, "agent.json");
129
+ if (existsSync(jsonCandidate)) {
130
+ const agent = await liate.load(jsonCandidate);
131
+ return { agent, sourcePath: jsonCandidate, sourceType: "json" };
132
+ }
133
+
134
+ const jsCandidate = resolve(cwd, "agent.js");
135
+ if (existsSync(jsCandidate)) {
136
+ const imported = await import(jsCandidate);
137
+ const ExportedClass = imported.default || Object.values(imported).find(
138
+ (val: any) => typeof val === "function" && (val.prototype instanceof liate || val === liate)
139
+ );
140
+ if (ExportedClass && typeof ExportedClass === "function") {
141
+ return { agent: new (ExportedClass as any)(), sourcePath: jsCandidate, sourceType: "javascript" };
142
+ }
143
+ }
144
+
145
+ // 3. Fallback: Ephemeral sovereign agent
146
+ const fallbackAgent = liate.from({
147
+ L: "sarvam/sarvam-105b-conversations",
148
+ A: { name: "liate-agent", intent: "Autonomous Sovereign Agent" },
149
+ E: { SARVAM_API_KEY: "$SARVAM_API_KEY" }
150
+ });
151
+
152
+ return { agent: fallbackAgent, sourceType: "ephemeral" };
153
+ }
@@ -0,0 +1,137 @@
1
+ import { z } from "zod";
2
+ import type { AgentModule } from "@/core/spec";
3
+
4
+ export const AUMSchema = z.object({
5
+ L: z.union([
6
+ z.string().min(1, "Model definition cannot be empty"),
7
+ z.object({
8
+ provider: z.string().optional(),
9
+ model: z.string(),
10
+ temperature: z.number().optional(),
11
+ maxTokens: z.number().optional(),
12
+ endpoint: z.string().optional()
13
+ }).passthrough()
14
+ ]),
15
+ I: z.object({
16
+ memory: z.string().optional(),
17
+ knowledge: z.union([z.string(), z.array(z.string()), z.record(z.string(), z.any())]).optional(),
18
+ state: z.record(z.string(), z.any()).optional()
19
+ }).passthrough().optional().default({}),
20
+ A: z.object({
21
+ name: z.string().min(1, "Agent name is required"),
22
+ version: z.string().optional().default("0.0.1"),
23
+ intent: z.string().optional(),
24
+ maxSteps: z.number().optional().default(10),
25
+ skills: z.array(z.string()).optional()
26
+ }).passthrough(),
27
+ T: z.union([
28
+ z.array(z.union([z.string(), z.record(z.string(), z.any())])),
29
+ z.record(z.string(), z.any())
30
+ ]).optional().default([]),
31
+ E: z.record(z.string(), z.string()).optional().default({})
32
+ });
33
+
34
+ export class AUM {
35
+ /**
36
+ * Normalizes module properties supporting pure LIATE authoring:
37
+ * 1. Shorthand: L, I, A, T, E
38
+ * 2. Full Name: LLM, Integration, Agent, Tools, Environment
39
+ * 3. Lowercase: llm, integration, agent, tools, environment
40
+ */
41
+ public static normalize(rawObj: any): any {
42
+ if (!rawObj || typeof rawObj !== "object") return rawObj;
43
+
44
+ const L = rawObj.L ?? rawObj.LLM ?? rawObj.llm;
45
+ const I = rawObj.I ?? rawObj.Integration ?? rawObj.integration;
46
+ const A = rawObj.A ?? rawObj.Agent ?? rawObj.agent;
47
+ const T = rawObj.T ?? rawObj.Tools ?? rawObj.tools;
48
+ const E = rawObj.E ?? rawObj.Environment ?? rawObj.environment;
49
+
50
+ return {
51
+ ...rawObj,
52
+ L,
53
+ I: I ?? {},
54
+ A: typeof A === "string" ? { name: A } : (A ?? {}),
55
+ T: T ?? [],
56
+ E: E ?? {}
57
+ };
58
+ }
59
+
60
+ public static parse(moduleOrJson: string | object): AgentModule {
61
+ let rawObj: any;
62
+
63
+ if (typeof moduleOrJson === "string") {
64
+ const trimmed = moduleOrJson.trim();
65
+ if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
66
+ try {
67
+ rawObj = JSON.parse(moduleOrJson);
68
+ } catch (err: any) {
69
+ throw new Error(`Failed to parse AUM module JSON: ${err.message}`);
70
+ }
71
+ } else if (trimmed.includes("class ") || trimmed.includes("extends liate") || trimmed.includes("export ")) {
72
+ try {
73
+ let code = trimmed
74
+ .replace(/import\s+[\s\S]*?;/g, "")
75
+ .replace(/export\s+default\s+/g, "")
76
+ .replace(/export\s+/g, "")
77
+ .replace(/extends\s+(liate|Liate)/g, "")
78
+ .replace(/if\s*\(import\.meta\.main\)[\s\S]*$/, "");
79
+
80
+ const match = code.match(/class\s+([A-Za-z0-9_]+)/);
81
+ const className = match ? match[1] : "Agent";
82
+ const fn = new Function(code + `\n return new ${className}();`);
83
+ const inst = fn();
84
+ rawObj = {
85
+ L: inst.L ?? inst.LLM ?? inst.llm,
86
+ I: inst.I ?? inst.Integration ?? inst.integration,
87
+ A: inst.A ?? inst.Agent ?? inst.agent,
88
+ T: inst.T ?? inst.Tools ?? inst.tools,
89
+ E: inst.E ?? inst.Environment ?? inst.environment
90
+ };
91
+ } catch (err: any) {
92
+ throw new Error(`Failed to parse agent TypeScript/JavaScript definition: ${err.message}`);
93
+ }
94
+ } else {
95
+ try {
96
+ rawObj = JSON.parse(moduleOrJson);
97
+ } catch (err: any) {
98
+ throw new Error(`Failed to parse AUM module: ${err.message}`);
99
+ }
100
+ }
101
+ } else {
102
+ rawObj = moduleOrJson;
103
+ }
104
+
105
+ const normalized = AUM.normalize(rawObj);
106
+ const result = AUMSchema.safeParse(normalized);
107
+
108
+ if (!result.success) {
109
+ const issues = result.error.issues.map((i) => `[${i.path.join(".")}] ${i.message}`).join(", ");
110
+ throw new Error(`Invalid AUM Module: ${issues}`);
111
+ }
112
+
113
+ return result.data as AgentModule;
114
+ }
115
+
116
+ public static resolveEnvironment(
117
+ module: AgentModule,
118
+ customEnv: Record<string, string | undefined> = process.env
119
+ ): AgentModule {
120
+ const resolvedE: Record<string, string> = {};
121
+
122
+ for (const [key, val] of Object.entries(module.E || {})) {
123
+ if (typeof val === "string" && val.startsWith("$")) {
124
+ const envVarName = val.slice(1);
125
+ resolvedE[key] = customEnv[envVarName] || "";
126
+ } else {
127
+ resolvedE[key] = String(val);
128
+ }
129
+ }
130
+
131
+ return {
132
+ ...module,
133
+ E: resolvedE
134
+ };
135
+ }
136
+ }
137
+
package/src/core/om.ts ADDED
@@ -0,0 +1,159 @@
1
+ import { Agent } from "@/layers/agent/harness";
2
+ import type { AgentRunResult, AgentExecutionOptions } from "@/layers/agent/types";
3
+ import type { AgentModule } from "@/core/spec";
4
+ import { AUM } from "@/core/aum";
5
+ import { ToolRegistry } from "@/layers/tools/registry";
6
+ import { EnvironmentResolver } from "@/layers/environment/sandbox";
7
+ import { Session } from "@/layers/integration/memory";
8
+
9
+ export * from "@/core/spec";
10
+ export * from "@/core/aum";
11
+
12
+ /**
13
+ * Core Orchestration Module (OM)
14
+ *
15
+ * "Where a Class is an Agent"
16
+ *
17
+ * 1 Class = 5 Properties (`L · I · A · T · E`) = 1:1 identical to agent.json
18
+ */
19
+ export class liate {
20
+ // 1. Shorthand: L · I · A · T · E
21
+ public L?: any;
22
+ public I?: any;
23
+ public A?: any;
24
+ public T?: any;
25
+ public E?: Record<string, string | undefined>;
26
+
27
+ // 2. Full Name: LLM · Integration · Agent · Tools · Environment
28
+ public LLM?: any;
29
+ public Integration?: any;
30
+ public Agent?: any;
31
+ public Tools?: any;
32
+ public Environment?: Record<string, string | undefined>;
33
+
34
+ // 3. Lowercase: llm · integration · agent · tools · environment
35
+ public llm?: any;
36
+ public integration?: any;
37
+ public agent?: any;
38
+ public tools?: any;
39
+ public environment?: Record<string, string | undefined>;
40
+
41
+ private _runner?: Agent;
42
+
43
+ /**
44
+ * Initializes and returns the underlying Agent harness instance
45
+ */
46
+ public async getRunner(): Promise<Agent> {
47
+ if (!this._runner) {
48
+ const module = this.toModule();
49
+ EnvironmentResolver.loadEnv();
50
+ const resolvedEnv = EnvironmentResolver.resolve(module.E || {});
51
+
52
+ const memory = new Session(module.I?.memory || "ephemeral");
53
+ const tools = await ToolRegistry.resolveTools(module.T || [], resolvedEnv);
54
+
55
+ const agentName = typeof module.A === "object" ? module.A.name : (module.A || this.constructor.name);
56
+ const agentIntent = typeof module.A === "object" ? module.A.intent : undefined;
57
+ const maxSteps = typeof module.A === "object" ? module.A.maxSteps : 10;
58
+ const skills = typeof module.A === "object" && Array.isArray(module.A.skills) ? module.A.skills : undefined;
59
+ const model = typeof module.L === "string" ? module.L : (module.L?.model || "sarvam/sarvam-105b-conversations");
60
+ const modelExtra = typeof module.L === "object" ? module.L : {};
61
+
62
+ this._runner = new Agent({
63
+ name: agentName,
64
+ intent: agentIntent,
65
+ model,
66
+ maxSteps,
67
+ skills,
68
+ memory,
69
+ tools,
70
+ ...modelExtra
71
+ } as any);
72
+ }
73
+ return this._runner;
74
+ }
75
+
76
+ /**
77
+ * Executes the agent on a user input via the autonomous ReAct reasoning loop
78
+ */
79
+ public async run(input: string, options?: AgentExecutionOptions): Promise<AgentRunResult> {
80
+ const runner = await this.getRunner();
81
+ return runner.run(input, options);
82
+ }
83
+
84
+ /**
85
+ * Gracefully closes all background transports, child processes, and MCP connections
86
+ */
87
+ public async close(): Promise<void> {
88
+ const { MCP } = await import("@/layers/tools/mcp");
89
+ await MCP.closeAll();
90
+ }
91
+
92
+ /**
93
+ * Instantiates an agent directly from an Agent Unified Module (AUM) or agent.json object
94
+ */
95
+ public static from(spec: any): liate {
96
+ const instance = new liate();
97
+ const parsed = AUM.parse(spec);
98
+ instance.L = parsed.L;
99
+ instance.I = parsed.I;
100
+ instance.A = parsed.A;
101
+ instance.T = parsed.T;
102
+ instance.E = parsed.E;
103
+ return instance;
104
+ }
105
+
106
+ /**
107
+ * Loads an agent directly from an agent.json file path or hub agent name
108
+ */
109
+ public static async load(filePath: string): Promise<liate> {
110
+ const fs = await import("fs/promises");
111
+ const { existsSync } = await import("fs");
112
+ const path = await import("path");
113
+
114
+ let resolvedPath = path.isAbsolute(filePath) ? filePath : path.resolve(process.cwd(), filePath);
115
+
116
+ if (!existsSync(resolvedPath)) {
117
+ // Check if it's a directory containing agent.json
118
+ if (existsSync(path.join(resolvedPath, "agent.json"))) {
119
+ resolvedPath = path.join(resolvedPath, "agent.json");
120
+ } else {
121
+ // Check in hub/agents
122
+ const hubCandidate = path.resolve(process.cwd(), "hub", "agents", filePath, "agent.json");
123
+ if (existsSync(hubCandidate)) {
124
+ resolvedPath = hubCandidate;
125
+ }
126
+ }
127
+ } else {
128
+ // If path exists and is a directory, look for agent.json inside
129
+ const stat = await fs.stat(resolvedPath);
130
+ if (stat.isDirectory()) {
131
+ const nested = path.join(resolvedPath, "agent.json");
132
+ if (existsSync(nested)) {
133
+ resolvedPath = nested;
134
+ }
135
+ }
136
+ }
137
+
138
+ const raw = await fs.readFile(resolvedPath, "utf-8");
139
+ const json = JSON.parse(raw);
140
+ return liate.from(json);
141
+ }
142
+
143
+ /**
144
+ * Exports the declarative L·I·A·T·E Agent Unified Module (AUM) representation
145
+ */
146
+ public toModule(): AgentModule {
147
+ const L = this.L ?? this.LLM ?? this.llm;
148
+ const I = this.I ?? this.Integration ?? this.integration;
149
+ const A = this.A ?? this.Agent ?? this.agent ?? { name: this.constructor.name };
150
+ const T = this.T ?? this.Tools ?? this.tools ?? [];
151
+ const E = this.E ?? this.Environment ?? this.environment ?? {};
152
+
153
+ return AUM.parse({ L, I, A, T, E });
154
+ }
155
+ }
156
+
157
+ // Clean alias
158
+ export const Liate = liate;
159
+
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Liate — Open Source AI Agents Framework
3
+ * Built for Sovereign AI Agents From India to the World.
4
+ *
5
+ * The 5 Layers:
6
+ * L[LM] — Sovereign Language Models & Reasoning
7
+ * I[ntegration] — Session Memory, Knowledge Context & State
8
+ * A[gent] — Identity, Name, Intent & Autonomous ReAct Loop
9
+ * T[ools] — Tools of MCP Server V2 (Stdio & Remote HTTP/SSE)
10
+ * E[nvironment] — Environment Variables, Secrets & Sandbox Configuration
11
+ */
12
+
13
+ /**
14
+ * [L] LLM Layer
15
+ * Sovereign Language Models: Sarvam AI 105B & OpenAI-compatible providers.
16
+ */
17
+ export type LayerL =
18
+ | string
19
+ | {
20
+ provider?: string;
21
+ model: string;
22
+ baseUrl?: string;
23
+ apiKey?: string;
24
+ temperature?: number;
25
+ maxTokens?: number;
26
+ };
27
+
28
+ export type ModelConfig = LayerL;
29
+
30
+ /**
31
+ * [I] Integration Layer
32
+ * Memory, Knowledge Context, and Persistence.
33
+ */
34
+ export interface LayerI {
35
+ knowledge?: string | string[] | Record<string, unknown>;
36
+ memory?: string;
37
+ state?: Record<string, unknown>;
38
+ [key: string]: unknown;
39
+ }
40
+
41
+ /**
42
+ * [A] Agent Layer
43
+ * Identity: Name, Intent, Version, maxSteps.
44
+ */
45
+ export interface LayerA {
46
+ name: string;
47
+ intent?: string;
48
+ version?: string;
49
+ system?: string;
50
+ maxSteps?: number;
51
+ skills?: string[];
52
+ [key: string]: unknown;
53
+ }
54
+
55
+ /**
56
+ * [T] Tools Layer
57
+ * Tools of MCP Server V2 (Local Stdio & Remote HTTP/SSE), Custom Handlers.
58
+ */
59
+ export interface ToolDefinition {
60
+ name?: string;
61
+ description?: string;
62
+ command?: string;
63
+ args?: string[];
64
+ url?: string;
65
+ tools?: string[];
66
+ parameters?: Record<string, unknown>;
67
+ execute?: (args: Record<string, unknown>) => Promise<unknown> | unknown;
68
+ [key: string]: unknown;
69
+ }
70
+
71
+ export type LayerT =
72
+ | Array<string | ToolDefinition>
73
+ | Record<string, ToolDefinition | string | Record<string, unknown>>;
74
+
75
+ /**
76
+ * [E] Environment Layer
77
+ * Configuration, API keys, and environment variables (.env).
78
+ */
79
+ export type LayerE = Record<string, string | undefined>;
80
+
81
+ /**
82
+ * The 5 Layers Agent Specification (AgentSpec / AgentModule)
83
+ * Supports authoring across 3 casing conventions:
84
+ * 1. Shorthand: L · I · A · T · E
85
+ * 2. Full Name: LLM · Integration · Agent · Tools · Environment
86
+ * 3. Lowercase: llm · integration · agent · tools · environment
87
+ */
88
+ export interface AgentSpec {
89
+ L: LayerL;
90
+ I?: LayerI;
91
+ A: LayerA | string;
92
+ T?: LayerT;
93
+ E?: LayerE;
94
+
95
+ // Full-name aliases
96
+ LLM?: LayerL;
97
+ llm?: LayerL;
98
+
99
+ Integration?: LayerI;
100
+ integration?: LayerI;
101
+
102
+ Agent?: LayerA | string;
103
+ agent?: LayerA | string;
104
+
105
+ Tools?: LayerT;
106
+ tools?: LayerT;
107
+
108
+ Environment?: LayerE;
109
+ environment?: LayerE;
110
+ }
111
+
112
+ export type AgentModule = AgentSpec;
@@ -0,0 +1,8 @@
1
+ // src/core/uuid.ts
2
+ import { randomUUID } from "node:crypto";
3
+
4
+ export function generateId(prefix?: string): string {
5
+ const id = randomUUID();
6
+ return prefix ? `${prefix}_${id}` : id;
7
+ }
8
+
@@ -0,0 +1,2 @@
1
+ // src/core/version.ts
2
+ export const VERSION = "0.1.6";
@@ -0,0 +1,118 @@
1
+ import { ReActLoop } from "@/layers/agent/loop";
2
+ import { SkillResolver } from "@/layers/agent/skills";
3
+ import type {
4
+ AgentTool,
5
+ AgentContext,
6
+ AgentRunResult,
7
+ AgentExecutionOptions,
8
+ AgentConfig
9
+ } from "@/layers/agent/types";
10
+ import type { MemoryProvider } from "@/layers/integration/types";
11
+ import { Session } from "@/layers/integration/memory";
12
+ import { LLMRouter } from "@/layers/llm/model";
13
+
14
+ export interface AgentOptions extends AgentConfig {
15
+ memory?: MemoryProvider | string;
16
+ apiKey?: string;
17
+ }
18
+
19
+ /**
20
+ * Layer [A] Agent Harness
21
+ * Jensen Huang's 3rd Element: The execution engine running the agent's autonomous ReAct loop.
22
+ */
23
+ export class Agent {
24
+ public readonly name: string;
25
+ public readonly intent: string;
26
+ public readonly model: string;
27
+ public readonly maxSteps: number;
28
+ public readonly skills: string[];
29
+ private memory: MemoryProvider;
30
+ private tools: Map<string, AgentTool> = new Map();
31
+ private apiKey?: string;
32
+ private extraOptions: Record<string, any>;
33
+
34
+ constructor(options: AgentOptions = { name: "agent" }) {
35
+ this.name = options.name || "agent";
36
+ this.intent = options.intent || "Autonomous AI Agent";
37
+ this.model = options.model || "sarvam/sarvam-105b-conversations";
38
+ this.maxSteps = options.maxSteps ?? 10;
39
+ this.skills = options.skills || [];
40
+ this.apiKey = options.apiKey;
41
+ this.extraOptions = { ...(options as any) };
42
+
43
+ // Resolve Layer [I] Session Memory
44
+ if (!options.memory) {
45
+ this.memory = new Session("ephemeral");
46
+ } else if (typeof options.memory === "string") {
47
+ this.memory = new Session(options.memory);
48
+ } else {
49
+ this.memory = options.memory;
50
+ }
51
+
52
+ if (options.tools) {
53
+ for (const t of options.tools) {
54
+ this.tools.set(t.name, t);
55
+ }
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Registers a tool dynamically
61
+ */
62
+ public addTool(tool: AgentTool): this {
63
+ this.tools.set(tool.name, tool);
64
+ return this;
65
+ }
66
+
67
+ /**
68
+ * Executes the agent on a user prompt via the autonomous ReAct reasoning loop
69
+ */
70
+ public async run(
71
+ prompt: string,
72
+ options?: AgentExecutionOptions
73
+ ): Promise<AgentRunResult> {
74
+ const skillSlugs = [...new Set([...this.skills, ...(options?.skills || [])])];
75
+ const resolvedSkills = skillSlugs.length > 0 ? await SkillResolver.resolveAll(skillSlugs) : [];
76
+ const skillPromptBlock = SkillResolver.formatSystemPrompt(resolvedSkills);
77
+
78
+ const context: AgentContext = {
79
+ agentName: this.name,
80
+ intent: this.intent + skillPromptBlock,
81
+ sessionId: this.memory.sessionId,
82
+ state: { skills: resolvedSkills.map((s) => s.slug) }
83
+ };
84
+
85
+ const combinedTools = [
86
+ ...Array.from(this.tools.values()),
87
+ ...(options?.tools || [])
88
+ ];
89
+
90
+ return ReActLoop.execute(
91
+ prompt,
92
+ LLMRouter,
93
+ this.memory,
94
+ combinedTools,
95
+ context,
96
+ {
97
+ ...this.extraOptions,
98
+ model: options?.model || this.model,
99
+ maxSteps: options?.maxSteps ?? this.maxSteps,
100
+ temperature: options?.temperature,
101
+ systemPrompt: options?.systemPrompt
102
+ ? options.systemPrompt + skillPromptBlock
103
+ : undefined,
104
+ apiKey: options?.apiKey || this.apiKey,
105
+ ...(options as any)
106
+ }
107
+ );
108
+ }
109
+
110
+ public getMemory(): MemoryProvider {
111
+ return this.memory;
112
+ }
113
+ }
114
+
115
+ // Clean Aliases
116
+ export const Harness = Agent;
117
+ export const AgentHarness = Agent;
118
+