@limo-labs/deity 0.1.0-alpha.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.
- package/README.md +519 -0
- package/dist/src/component.d.ts +19 -0
- package/dist/src/component.d.ts.map +1 -0
- package/dist/src/component.js +2 -0
- package/dist/src/component.js.map +1 -0
- package/dist/src/context/context-scope.d.ts +24 -0
- package/dist/src/context/context-scope.d.ts.map +1 -0
- package/dist/src/context/context-scope.js +19 -0
- package/dist/src/context/context-scope.js.map +1 -0
- package/dist/src/context/memory-view.d.ts +62 -0
- package/dist/src/context/memory-view.d.ts.map +1 -0
- package/dist/src/context/memory-view.js +104 -0
- package/dist/src/context/memory-view.js.map +1 -0
- package/dist/src/context/scoped-context.d.ts +51 -0
- package/dist/src/context/scoped-context.d.ts.map +1 -0
- package/dist/src/context/scoped-context.js +74 -0
- package/dist/src/context/scoped-context.js.map +1 -0
- package/dist/src/context/scoped-execution-context.d.ts +55 -0
- package/dist/src/context/scoped-execution-context.d.ts.map +1 -0
- package/dist/src/context/scoped-execution-context.js +78 -0
- package/dist/src/context/scoped-execution-context.js.map +1 -0
- package/dist/src/conversation/conversation-manager.d.ts +272 -0
- package/dist/src/conversation/conversation-manager.d.ts.map +1 -0
- package/dist/src/conversation/conversation-manager.js +11 -0
- package/dist/src/conversation/conversation-manager.js.map +1 -0
- package/dist/src/conversation/conversation-pruner.d.ts +190 -0
- package/dist/src/conversation/conversation-pruner.d.ts.map +1 -0
- package/dist/src/conversation/conversation-pruner.js +274 -0
- package/dist/src/conversation/conversation-pruner.js.map +1 -0
- package/dist/src/conversation/conversation-tree.d.ts +185 -0
- package/dist/src/conversation/conversation-tree.d.ts.map +1 -0
- package/dist/src/conversation/conversation-tree.js +288 -0
- package/dist/src/conversation/conversation-tree.js.map +1 -0
- package/dist/src/conversation/file-conversation-store.d.ts +93 -0
- package/dist/src/conversation/file-conversation-store.d.ts.map +1 -0
- package/dist/src/conversation/file-conversation-store.js +284 -0
- package/dist/src/conversation/file-conversation-store.js.map +1 -0
- package/dist/src/conversation/in-memory-conversation-store.d.ts +36 -0
- package/dist/src/conversation/in-memory-conversation-store.d.ts.map +1 -0
- package/dist/src/conversation/in-memory-conversation-store.js +146 -0
- package/dist/src/conversation/in-memory-conversation-store.js.map +1 -0
- package/dist/src/copilot-adapter.d.ts +33 -0
- package/dist/src/copilot-adapter.d.ts.map +1 -0
- package/dist/src/copilot-adapter.js +119 -0
- package/dist/src/copilot-adapter.js.map +1 -0
- package/dist/src/file-trace-enhanced.d.ts +123 -0
- package/dist/src/file-trace-enhanced.d.ts.map +1 -0
- package/dist/src/file-trace-enhanced.js +177 -0
- package/dist/src/file-trace-enhanced.js.map +1 -0
- package/dist/src/file-trace.d.ts +24 -0
- package/dist/src/file-trace.d.ts.map +1 -0
- package/dist/src/file-trace.js +60 -0
- package/dist/src/file-trace.js.map +1 -0
- package/dist/src/index.d.ts +63 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +40 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/json-store.d.ts +27 -0
- package/dist/src/json-store.d.ts.map +1 -0
- package/dist/src/json-store.js +93 -0
- package/dist/src/json-store.js.map +1 -0
- package/dist/src/llm.d.ts +35 -0
- package/dist/src/llm.d.ts.map +1 -0
- package/dist/src/llm.js +2 -0
- package/dist/src/llm.js.map +1 -0
- package/dist/src/memory/cold-storage.d.ts +60 -0
- package/dist/src/memory/cold-storage.d.ts.map +1 -0
- package/dist/src/memory/cold-storage.js +132 -0
- package/dist/src/memory/cold-storage.js.map +1 -0
- package/dist/src/memory/compression.d.ts +161 -0
- package/dist/src/memory/compression.d.ts.map +1 -0
- package/dist/src/memory/compression.js +193 -0
- package/dist/src/memory/compression.js.map +1 -0
- package/dist/src/memory/hot-memory.d.ts +69 -0
- package/dist/src/memory/hot-memory.d.ts.map +1 -0
- package/dist/src/memory/hot-memory.js +116 -0
- package/dist/src/memory/hot-memory.js.map +1 -0
- package/dist/src/memory/memory-budget.d.ts +162 -0
- package/dist/src/memory/memory-budget.d.ts.map +1 -0
- package/dist/src/memory/memory-budget.js +241 -0
- package/dist/src/memory/memory-budget.js.map +1 -0
- package/dist/src/memory/memory-config.d.ts +419 -0
- package/dist/src/memory/memory-config.d.ts.map +1 -0
- package/dist/src/memory/memory-config.js +297 -0
- package/dist/src/memory/memory-config.js.map +1 -0
- package/dist/src/memory/prefetcher.d.ts +137 -0
- package/dist/src/memory/prefetcher.d.ts.map +1 -0
- package/dist/src/memory/prefetcher.js +186 -0
- package/dist/src/memory/prefetcher.js.map +1 -0
- package/dist/src/memory/tiered-memory.d.ts +116 -0
- package/dist/src/memory/tiered-memory.d.ts.map +1 -0
- package/dist/src/memory/tiered-memory.js +215 -0
- package/dist/src/memory/tiered-memory.js.map +1 -0
- package/dist/src/memory/warm-storage.d.ts +74 -0
- package/dist/src/memory/warm-storage.d.ts.map +1 -0
- package/dist/src/memory/warm-storage.js +207 -0
- package/dist/src/memory/warm-storage.js.map +1 -0
- package/dist/src/openai-adapter.d.ts +20 -0
- package/dist/src/openai-adapter.d.ts.map +1 -0
- package/dist/src/openai-adapter.js +73 -0
- package/dist/src/openai-adapter.js.map +1 -0
- package/dist/src/parser.d.ts +27 -0
- package/dist/src/parser.d.ts.map +1 -0
- package/dist/src/parser.js +76 -0
- package/dist/src/parser.js.map +1 -0
- package/dist/src/runtime.d.ts +172 -0
- package/dist/src/runtime.d.ts.map +1 -0
- package/dist/src/runtime.js +436 -0
- package/dist/src/runtime.js.map +1 -0
- package/dist/src/schema-utils.d.ts +7 -0
- package/dist/src/schema-utils.d.ts.map +1 -0
- package/dist/src/schema-utils.js +71 -0
- package/dist/src/schema-utils.js.map +1 -0
- package/dist/src/stage.d.ts +139 -0
- package/dist/src/stage.d.ts.map +1 -0
- package/dist/src/stage.js +2 -0
- package/dist/src/stage.js.map +1 -0
- package/dist/src/store.d.ts +51 -0
- package/dist/src/store.d.ts.map +1 -0
- package/dist/src/store.js +2 -0
- package/dist/src/store.js.map +1 -0
- package/dist/src/tool.d.ts +12 -0
- package/dist/src/tool.d.ts.map +1 -0
- package/dist/src/tool.js +2 -0
- package/dist/src/tool.js.map +1 -0
- package/dist/src/trace.d.ts +60 -0
- package/dist/src/trace.d.ts.map +1 -0
- package/dist/src/trace.js +2 -0
- package/dist/src/trace.js.map +1 -0
- package/dist/src/validator.d.ts +17 -0
- package/dist/src/validator.d.ts.map +1 -0
- package/dist/src/validator.js +21 -0
- package/dist/src/validator.js.map +1 -0
- package/dist/src/workflow.d.ts +192 -0
- package/dist/src/workflow.d.ts.map +1 -0
- package/dist/src/workflow.js +50 -0
- package/dist/src/workflow.js.map +1 -0
- package/package.json +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
# @limo-deity/core
|
|
2
|
+
|
|
3
|
+
> **Deterministic orchestration runtime for AI agents with built-in checkpoint & resume capabilities.**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@limo-deity/core)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://nodejs.org/)
|
|
8
|
+
[](../../LICENSE)
|
|
9
|
+
|
|
10
|
+
## What is @limo-deity/core?
|
|
11
|
+
|
|
12
|
+
The core runtime for building **long-running AI agents** with:
|
|
13
|
+
|
|
14
|
+
- ✅ **Deterministic execution** — Reproducible results via checkpointing
|
|
15
|
+
- ✅ **Automatic checkpoint & resume** — Crash-resistant workflows
|
|
16
|
+
- ✅ **Schema + semantic validation** — Every output validated before proceeding
|
|
17
|
+
- ✅ **Complete execution tracing** — Full logs for debugging and auditing
|
|
18
|
+
- ✅ **Type-safe** — Full TypeScript support with Zod schemas
|
|
19
|
+
- ✅ **Tool calling** — Built-in function calling loop
|
|
20
|
+
- ✅ **Retry with feedback** — LLM self-correction via validation errors
|
|
21
|
+
|
|
22
|
+
**Limo-Deity is NOT a prompt library.** It's an orchestration runtime that treats LLMs as controlled computation units within a deterministic workflow.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @limo-deity/core zod
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Requirements:**
|
|
33
|
+
- Node.js ≥ 20.0.0
|
|
34
|
+
- npm ≥ 9.0.0
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Quick Start
|
|
39
|
+
|
|
40
|
+
### 1. Define a Component
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { AgentComponent, ExecutionContext } from "@limo-deity/core";
|
|
44
|
+
import { z } from "zod";
|
|
45
|
+
|
|
46
|
+
const SummaryComponent: AgentComponent<
|
|
47
|
+
{ text: string },
|
|
48
|
+
{ summary: string; wordCount: number }
|
|
49
|
+
> = {
|
|
50
|
+
id: "SummaryComponent",
|
|
51
|
+
|
|
52
|
+
inputSchema: z.object({
|
|
53
|
+
text: z.string().min(1)
|
|
54
|
+
}),
|
|
55
|
+
|
|
56
|
+
outputSchema: z.object({
|
|
57
|
+
summary: z.string(),
|
|
58
|
+
wordCount: z.number().int().positive(),
|
|
59
|
+
}),
|
|
60
|
+
|
|
61
|
+
buildPrompt(ctx: ExecutionContext<{ text: string }>) {
|
|
62
|
+
return [
|
|
63
|
+
{
|
|
64
|
+
role: "system",
|
|
65
|
+
content: "You are a summarization assistant. Output JSON only.",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
role: "user",
|
|
69
|
+
content: `Summarize: ${ctx.inputs.text}\\n\\nJSON: { "summary": "...", "wordCount": 123 }`,
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
validate(output) {
|
|
75
|
+
if (output.summary.length < 10) {
|
|
76
|
+
return { valid: false, errors: ["Summary too short"] };
|
|
77
|
+
}
|
|
78
|
+
return { valid: true };
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
retry: {
|
|
82
|
+
maxAttempts: 3,
|
|
83
|
+
feedbackOnError: true, // Auto-inject errors into retry prompts
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 2. Create and Run a Workflow
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import {
|
|
92
|
+
defineWorkflow,
|
|
93
|
+
runWorkflow,
|
|
94
|
+
JsonFileStore,
|
|
95
|
+
FileTraceLogger,
|
|
96
|
+
CopilotAdapter,
|
|
97
|
+
} from "@limo-deity/core";
|
|
98
|
+
|
|
99
|
+
// Define workflow
|
|
100
|
+
const workflow = defineWorkflow({
|
|
101
|
+
name: "text-summarization",
|
|
102
|
+
defaultModel: {
|
|
103
|
+
adapter: new CopilotAdapter({
|
|
104
|
+
githubToken: process.env.GITHUB_TOKEN,
|
|
105
|
+
}),
|
|
106
|
+
config: { temperature: 0 },
|
|
107
|
+
},
|
|
108
|
+
steps: [SummaryComponent],
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// Set up infrastructure
|
|
112
|
+
const store = new JsonFileStore("./checkpoints");
|
|
113
|
+
const trace = new FileTraceLogger("./trace.jsonl");
|
|
114
|
+
|
|
115
|
+
// Run workflow
|
|
116
|
+
const result = await runWorkflow(
|
|
117
|
+
workflow,
|
|
118
|
+
{ text: "Your input text here..." },
|
|
119
|
+
store,
|
|
120
|
+
trace
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
console.log(result.SummaryComponent.summary);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 3. Checkpoint & Resume
|
|
127
|
+
|
|
128
|
+
If the workflow crashes, simply re-run it:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
// Re-run the same workflow - it will resume from the last checkpoint
|
|
132
|
+
const result = await runWorkflow(workflow, inputs, store, trace);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Completed stages are skipped automatically** — only incomplete work is re-executed.
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Core Features
|
|
140
|
+
|
|
141
|
+
### 🔄 Deterministic Execution
|
|
142
|
+
|
|
143
|
+
- **Prompt hash invalidation** — Checkpoints auto-invalidate when component code changes
|
|
144
|
+
- **Reproducible results** — Same checkpoints → same outputs
|
|
145
|
+
- **No side effects** — Runtime controls all I/O
|
|
146
|
+
|
|
147
|
+
### ✅ Validation Gates
|
|
148
|
+
|
|
149
|
+
Every component output must pass:
|
|
150
|
+
1. **Schema validation** (Zod) — Type checking
|
|
151
|
+
2. **Semantic validation** (custom logic) — Business rules
|
|
152
|
+
|
|
153
|
+
No stage completes without validation passing.
|
|
154
|
+
|
|
155
|
+
### 🔧 Tool Calling
|
|
156
|
+
|
|
157
|
+
Built-in function calling with automatic loop management:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
const component: AgentComponent<Input, Output> = {
|
|
161
|
+
// ... other fields ...
|
|
162
|
+
|
|
163
|
+
tools: [
|
|
164
|
+
{
|
|
165
|
+
name: "search_database",
|
|
166
|
+
description: "Search for information in the database",
|
|
167
|
+
inputSchema: z.object({ query: z.string() }),
|
|
168
|
+
async execute(input) {
|
|
169
|
+
return await database.search(input.query);
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
};
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Runtime executes tool calls, LLM never has direct access.
|
|
177
|
+
|
|
178
|
+
### 🔁 Retry with Feedback
|
|
179
|
+
|
|
180
|
+
Failed validations automatically feed back into retry prompts:
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
retry: {
|
|
184
|
+
maxAttempts: 3,
|
|
185
|
+
feedbackOnError: true, // Default: true
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**Example feedback loop:**
|
|
190
|
+
1. LLM outputs: `{ "summary": "Hi" }` ❌
|
|
191
|
+
2. Validation fails: "Summary too short"
|
|
192
|
+
3. Runtime automatically adds to next prompt:
|
|
193
|
+
```
|
|
194
|
+
Previous attempt failed validation:
|
|
195
|
+
- Summary too short
|
|
196
|
+
Please correct your output.
|
|
197
|
+
```
|
|
198
|
+
4. LLM self-corrects → valid output ✅
|
|
199
|
+
|
|
200
|
+
### 📝 Complete Tracing
|
|
201
|
+
|
|
202
|
+
All execution logged to JSONL:
|
|
203
|
+
|
|
204
|
+
```jsonl
|
|
205
|
+
{"type":"stage_start","stageId":"SummaryComponent","timestamp":"..."}
|
|
206
|
+
{"type":"llm_call","messages":[...],"timestamp":"..."}
|
|
207
|
+
{"type":"llm_response","content":"...","timestamp":"..."}
|
|
208
|
+
{"type":"validation_passed","output":{...},"timestamp":"..."}
|
|
209
|
+
{"type":"stage_complete","stageId":"SummaryComponent","timestamp":"..."}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Architecture
|
|
215
|
+
|
|
216
|
+
### High-Level Flow
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
User Components (AgentComponent<I, O>)
|
|
220
|
+
↓
|
|
221
|
+
Workflow Definition (defineWorkflow)
|
|
222
|
+
↓
|
|
223
|
+
Runtime Loop (runWorkflow)
|
|
224
|
+
↓
|
|
225
|
+
Execution per step:
|
|
226
|
+
1. Check checkpoint (skip if valid)
|
|
227
|
+
2. Build prompt (Message[])
|
|
228
|
+
3. Call LLM (with tools if declared)
|
|
229
|
+
4. Parse output (JSON extraction + Zod validation)
|
|
230
|
+
5. Semantic validation (custom logic)
|
|
231
|
+
6. Retry with error feedback (if validation fails)
|
|
232
|
+
7. Save checkpoint + trace
|
|
233
|
+
↓
|
|
234
|
+
State Store + Trace Logger
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Key Abstractions
|
|
238
|
+
|
|
239
|
+
| Abstraction | Purpose |
|
|
240
|
+
|-------------|---------|
|
|
241
|
+
| `AgentComponent<I, O>` | User-defined workflow step |
|
|
242
|
+
| `ExecutionContext<I>` | Runtime data available to a step |
|
|
243
|
+
| `LLMAdapter` | LLM provider abstraction |
|
|
244
|
+
| `StateStore` | Checkpoint storage interface |
|
|
245
|
+
| `TraceLogger` | Execution log interface |
|
|
246
|
+
| `Tool` | Function calling abstraction |
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## LLM Adapters
|
|
251
|
+
|
|
252
|
+
### Built-in Adapters
|
|
253
|
+
|
|
254
|
+
#### GitHub Copilot
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
import { CopilotAdapter } from "@limo-deity/core";
|
|
258
|
+
|
|
259
|
+
const adapter = new CopilotAdapter({
|
|
260
|
+
githubToken: process.env.GITHUB_TOKEN,
|
|
261
|
+
model: "gpt-4o", // optional
|
|
262
|
+
});
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**Authentication**: GitHub token via device flow OAuth.
|
|
266
|
+
|
|
267
|
+
#### OpenAI
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
import { OpenAIAdapter } from "@limo-deity/core";
|
|
271
|
+
|
|
272
|
+
const adapter = new OpenAIAdapter({
|
|
273
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
274
|
+
model: "gpt-4o",
|
|
275
|
+
});
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Custom Adapters
|
|
279
|
+
|
|
280
|
+
Implement the `LLMAdapter` interface:
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
import { LLMAdapter, LLMResponse, Message, Tool } from "@limo-deity/core";
|
|
284
|
+
|
|
285
|
+
export class MyLLMAdapter implements LLMAdapter {
|
|
286
|
+
async generate(
|
|
287
|
+
messages: Message[],
|
|
288
|
+
tools?: Tool[],
|
|
289
|
+
config?: GenerationConfig
|
|
290
|
+
): Promise<LLMResponse> {
|
|
291
|
+
// Your implementation
|
|
292
|
+
return {
|
|
293
|
+
content: "...",
|
|
294
|
+
toolCalls: [...], // optional
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
## API Overview
|
|
303
|
+
|
|
304
|
+
### Core Functions
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
// Define a workflow
|
|
308
|
+
function defineWorkflow(config: WorkflowConfig): Workflow
|
|
309
|
+
|
|
310
|
+
// Run a workflow
|
|
311
|
+
function runWorkflow<I>(
|
|
312
|
+
workflow: Workflow,
|
|
313
|
+
inputs: I,
|
|
314
|
+
store: StateStore,
|
|
315
|
+
trace: TraceLogger,
|
|
316
|
+
conversation?: ConversationManager
|
|
317
|
+
): Promise<Record<string, unknown>>
|
|
318
|
+
|
|
319
|
+
// Parse and validate LLM output
|
|
320
|
+
function parseOutput<T>(
|
|
321
|
+
response: string,
|
|
322
|
+
schema: ZodSchema<T>
|
|
323
|
+
): { success: true; data: T } | { success: false; error: string }
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### Core Types
|
|
327
|
+
|
|
328
|
+
```typescript
|
|
329
|
+
interface AgentComponent<I, O> {
|
|
330
|
+
id: string;
|
|
331
|
+
inputSchema: ZodSchema<I>;
|
|
332
|
+
outputSchema: ZodSchema<O>;
|
|
333
|
+
buildPrompt(ctx: ExecutionContext<I>): Message[];
|
|
334
|
+
validate(output: O, ctx: ExecutionContext<I>): ValidationResult;
|
|
335
|
+
tools?: Tool[];
|
|
336
|
+
retry?: RetryConfig;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
interface ExecutionContext<I> {
|
|
340
|
+
inputs: I;
|
|
341
|
+
previousOutputs: Record<string, unknown>;
|
|
342
|
+
getOutput<T>(stageId: string): T;
|
|
343
|
+
store: StateStore;
|
|
344
|
+
trace: TraceLogger;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
interface Message {
|
|
348
|
+
role: "system" | "user" | "assistant" | "tool";
|
|
349
|
+
content: string;
|
|
350
|
+
toolCallId?: string;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
interface ValidationResult {
|
|
354
|
+
valid: boolean;
|
|
355
|
+
errors?: string[];
|
|
356
|
+
}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
See [API Documentation](../../doc/API.md) for complete reference.
|
|
360
|
+
|
|
361
|
+
---
|
|
362
|
+
|
|
363
|
+
## Deity 2.0 Features
|
|
364
|
+
|
|
365
|
+
### Tiered Memory System (Alpha)
|
|
366
|
+
|
|
367
|
+
Automatic hot/warm/cold storage management:
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
const workflow = defineWorkflow({
|
|
371
|
+
name: "my-workflow",
|
|
372
|
+
memoryConfig: 'production', // Uses tiered memory
|
|
373
|
+
steps: [/* ... */],
|
|
374
|
+
});
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
**Status**: POC complete, production integration in progress.
|
|
378
|
+
|
|
379
|
+
See [Memory System Guide](../../doc/MEMORY_SYSTEM.md) for details.
|
|
380
|
+
|
|
381
|
+
### Context Scoping (Alpha)
|
|
382
|
+
|
|
383
|
+
Control which steps can access which data:
|
|
384
|
+
|
|
385
|
+
```typescript
|
|
386
|
+
const component: AgentComponent<I, O> = {
|
|
387
|
+
scope: ["Step1", "Step2"], // Only access these steps
|
|
388
|
+
// ...
|
|
389
|
+
};
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
**Status**: POC complete.
|
|
393
|
+
|
|
394
|
+
See [Context System Guide](../../doc/CONTEXT_SYSTEM.md) for details.
|
|
395
|
+
|
|
396
|
+
---
|
|
397
|
+
|
|
398
|
+
## Examples
|
|
399
|
+
|
|
400
|
+
### Multi-Step Workflow
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
const workflow = defineWorkflow({
|
|
404
|
+
name: "research-pipeline",
|
|
405
|
+
defaultModel: { adapter: llm },
|
|
406
|
+
steps: [
|
|
407
|
+
IndexComponent, // Step 1: Index repository
|
|
408
|
+
AnalyzeComponent, // Step 2: Analyze code (uses Step 1 output)
|
|
409
|
+
ReportComponent, // Step 3: Generate report (uses Step 1 & 2)
|
|
410
|
+
],
|
|
411
|
+
});
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### Accessing Previous Outputs
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
buildPrompt(ctx: ExecutionContext<Input>) {
|
|
418
|
+
// Type-safe access to previous step outputs
|
|
419
|
+
const indexData = ctx.getOutput<IndexOutput>("IndexComponent");
|
|
420
|
+
|
|
421
|
+
return [
|
|
422
|
+
{
|
|
423
|
+
role: "user",
|
|
424
|
+
content: `Analyze these files: ${indexData.files.join(", ")}`,
|
|
425
|
+
},
|
|
426
|
+
];
|
|
427
|
+
}
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
### Custom Validation
|
|
431
|
+
|
|
432
|
+
```typescript
|
|
433
|
+
validate(output: GraphOutput, ctx: ExecutionContext<Input>) {
|
|
434
|
+
const errors: string[] = [];
|
|
435
|
+
|
|
436
|
+
if (output.nodes.length === 0) {
|
|
437
|
+
errors.push("Graph has no nodes");
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// Check references
|
|
441
|
+
const nodeIds = new Set(output.nodes.map(n => n.id));
|
|
442
|
+
for (const edge of output.edges) {
|
|
443
|
+
if (!nodeIds.has(edge.from)) {
|
|
444
|
+
errors.push(`Invalid edge: ${edge.from} does not exist`);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return errors.length > 0
|
|
449
|
+
? { valid: false, errors }
|
|
450
|
+
: { valid: true };
|
|
451
|
+
}
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
See [examples directory](../example-agent/) for complete working examples.
|
|
455
|
+
|
|
456
|
+
---
|
|
457
|
+
|
|
458
|
+
## Documentation
|
|
459
|
+
|
|
460
|
+
- **[Main README](../../README.md)** — Project overview and quick start
|
|
461
|
+
- **[Philosophy](../../doc/philosophy.md)** — Design principles and positioning
|
|
462
|
+
- **[Design Document](../../doc/design.md)** — Technical specification
|
|
463
|
+
- **[API Reference](../../doc/API.md)** — Complete API documentation
|
|
464
|
+
- **[Best Practices](../../doc/BEST_PRACTICES.md)** — Production tips
|
|
465
|
+
- **[Memory System](../../doc/MEMORY_SYSTEM.md)** — Tiered memory guide
|
|
466
|
+
- **[Migration Guide](../../doc/MIGRATION_GUIDE.md)** — v1.x → v2.0 upgrade
|
|
467
|
+
- **[CLAUDE.md](../../CLAUDE.md)** — AI assistant collaboration guide
|
|
468
|
+
|
|
469
|
+
---
|
|
470
|
+
|
|
471
|
+
## Development
|
|
472
|
+
|
|
473
|
+
### Building
|
|
474
|
+
|
|
475
|
+
```bash
|
|
476
|
+
npm run build
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
### Testing
|
|
480
|
+
|
|
481
|
+
```bash
|
|
482
|
+
# Run tests once
|
|
483
|
+
npm test
|
|
484
|
+
|
|
485
|
+
# Watch mode
|
|
486
|
+
npm run test:watch
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
### Cleaning
|
|
490
|
+
|
|
491
|
+
```bash
|
|
492
|
+
npm run clean
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
---
|
|
496
|
+
|
|
497
|
+
## Contributing
|
|
498
|
+
|
|
499
|
+
See [CONTRIBUTING.md](../../CONTRIBUTING.md) for guidelines.
|
|
500
|
+
|
|
501
|
+
---
|
|
502
|
+
|
|
503
|
+
## License
|
|
504
|
+
|
|
505
|
+
MIT © Limo-Deity Contributors
|
|
506
|
+
|
|
507
|
+
See [LICENSE](../../LICENSE) for details.
|
|
508
|
+
|
|
509
|
+
---
|
|
510
|
+
|
|
511
|
+
## Support
|
|
512
|
+
|
|
513
|
+
- **Issues**: [GitHub Issues](https://github.com/Limo-Deity/Limo-Deity/issues)
|
|
514
|
+
- **Discussions**: [GitHub Discussions](https://github.com/Limo-Deity/Limo-Deity/discussions)
|
|
515
|
+
- **Documentation**: [Full Docs](../../doc/)
|
|
516
|
+
|
|
517
|
+
---
|
|
518
|
+
|
|
519
|
+
**Built with ❤️ by the Limo-Deity community**
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message type for LLM communication.
|
|
3
|
+
* Supports system/user/assistant roles matching modern LLM APIs.
|
|
4
|
+
*/
|
|
5
|
+
export interface Message {
|
|
6
|
+
role: "system" | "user" | "assistant" | "tool";
|
|
7
|
+
content: string;
|
|
8
|
+
/** Tool call ID this message is responding to (for role: "tool") */
|
|
9
|
+
toolCallId?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Structured validation result with error details.
|
|
13
|
+
* Errors are used for trace logging and retry feedback.
|
|
14
|
+
*/
|
|
15
|
+
export interface ValidationResult {
|
|
16
|
+
valid: boolean;
|
|
17
|
+
errors?: string[];
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/component.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../src/component.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines visibility rules for a context scope.
|
|
3
|
+
*/
|
|
4
|
+
export interface ContextScope {
|
|
5
|
+
/** Name of this scope (for debugging) */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Stage IDs visible in this scope ("*" for all) */
|
|
8
|
+
visibleStages: string[] | "*";
|
|
9
|
+
/** Whether this scope can write to memory (default: true) */
|
|
10
|
+
canWrite?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Access mode for memory operations.
|
|
14
|
+
*/
|
|
15
|
+
export type AccessMode = "read" | "write";
|
|
16
|
+
/**
|
|
17
|
+
* Check if a stage ID is visible in a scope.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isStageVisible(scope: ContextScope, stageId: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Check if an access mode is allowed in a scope.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isAccessAllowed(scope: ContextScope, mode: AccessMode): boolean;
|
|
24
|
+
//# sourceMappingURL=context-scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-scope.d.ts","sourceRoot":"","sources":["../../../src/context/context-scope.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,aAAa,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAC9B,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC;AAE1C;;GAEG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,MAAM,GACd,OAAO,CAKT;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,UAAU,GACf,OAAO,CAKT"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a stage ID is visible in a scope.
|
|
3
|
+
*/
|
|
4
|
+
export function isStageVisible(scope, stageId) {
|
|
5
|
+
if (scope.visibleStages === "*") {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
return scope.visibleStages.includes(stageId);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Check if an access mode is allowed in a scope.
|
|
12
|
+
*/
|
|
13
|
+
export function isAccessAllowed(scope, mode) {
|
|
14
|
+
if (mode === "read") {
|
|
15
|
+
return true; // Reading is always allowed
|
|
16
|
+
}
|
|
17
|
+
return scope.canWrite !== false; // Writing allowed by default
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=context-scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-scope.js","sourceRoot":"","sources":["../../../src/context/context-scope.ts"],"names":[],"mappings":"AAiBA;;GAEG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAmB,EACnB,OAAe;IAEf,IAAI,KAAK,CAAC,aAAa,KAAK,GAAG,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAC/C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAC7B,KAAmB,EACnB,IAAgB;IAEhB,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC,CAAC,4BAA4B;IAC3C,CAAC;IACD,OAAO,KAAK,CAAC,QAAQ,KAAK,KAAK,CAAC,CAAC,6BAA6B;AAChE,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { TieredMemoryManager } from "../memory/tiered-memory.js";
|
|
2
|
+
import type { ContextScope } from "./context-scope.js";
|
|
3
|
+
/**
|
|
4
|
+
* Memory view with access control based on context scope.
|
|
5
|
+
* Wraps TieredMemoryManager and enforces visibility rules.
|
|
6
|
+
*/
|
|
7
|
+
export declare class MemoryView {
|
|
8
|
+
private memory;
|
|
9
|
+
private scope;
|
|
10
|
+
constructor(memory: TieredMemoryManager, scope: ContextScope);
|
|
11
|
+
/**
|
|
12
|
+
* Get a value from memory.
|
|
13
|
+
* Throws if the key's stage is not visible in this scope.
|
|
14
|
+
*/
|
|
15
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
16
|
+
/**
|
|
17
|
+
* Set a value in memory.
|
|
18
|
+
* Throws if write access is not allowed or key's stage is not visible.
|
|
19
|
+
*/
|
|
20
|
+
set<T>(key: string, value: T): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Check if a key exists in memory.
|
|
23
|
+
* Throws if the key's stage is not visible in this scope.
|
|
24
|
+
*/
|
|
25
|
+
has(key: string): Promise<boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* Delete a value from memory.
|
|
28
|
+
* Throws if write access is not allowed or key's stage is not visible.
|
|
29
|
+
*/
|
|
30
|
+
delete(key: string): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Pin a key to prevent eviction.
|
|
33
|
+
* Throws if write access is not allowed or key's stage is not visible.
|
|
34
|
+
*/
|
|
35
|
+
pin(key: string): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Unpin a key.
|
|
38
|
+
* Throws if write access is not allowed or key's stage is not visible.
|
|
39
|
+
*/
|
|
40
|
+
unpin(key: string): void;
|
|
41
|
+
/**
|
|
42
|
+
* Get the current scope.
|
|
43
|
+
*/
|
|
44
|
+
getScope(): ContextScope;
|
|
45
|
+
/**
|
|
46
|
+
* Check if access to a key is allowed in this scope.
|
|
47
|
+
* Throws AccessDeniedError if access is not allowed.
|
|
48
|
+
*/
|
|
49
|
+
private checkAccess;
|
|
50
|
+
/**
|
|
51
|
+
* Extract stage ID from a memory key.
|
|
52
|
+
* Assumes format "stage:StageId" or just "StageId".
|
|
53
|
+
*/
|
|
54
|
+
private extractStageId;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Error thrown when access is denied due to scope restrictions.
|
|
58
|
+
*/
|
|
59
|
+
export declare class AccessDeniedError extends Error {
|
|
60
|
+
constructor(message: string);
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=memory-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-view.d.ts","sourceRoot":"","sources":["../../../src/context/memory-view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,oBAAoB,CAAC;AAGnE;;;GAGG;AACH,qBAAa,UAAU;IAEnB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,KAAK;gBADL,MAAM,EAAE,mBAAmB,EAC3B,KAAK,EAAE,YAAY;IAG7B;;;OAGG;IACG,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAKjD;;;OAGG;IACG,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlD;;;OAGG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKxC;;;OAGG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxC;;;OAGG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKrC;;;OAGG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAKxB;;OAEG;IACH,QAAQ,IAAI,YAAY;IAIxB;;;OAGG;IACH,OAAO,CAAC,WAAW;IAmBnB;;;OAGG;IACH,OAAO,CAAC,cAAc;CAOvB;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,EAAE,MAAM;CAI5B"}
|