rice-node-sdk 1.0.3 → 1.0.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Rice Node SDK
2
2
 
3
- Unified Node.js/TypeScript SDK for RiceDB (Persistent Semantic Database) and State (AI Memory).
3
+ Node.js/TypeScript SDK for Rice
4
4
 
5
5
  ## Installation
6
6
 
@@ -19,19 +19,19 @@ import { Client } from "rice-node-sdk";
19
19
  const client = new Client();
20
20
  await client.connect();
21
21
 
22
- // --- Storage (RiceDB) ---
22
+ // --- Storage ---
23
23
  // Insert data
24
24
  await client.storage.insert(
25
25
  "unique-node-id",
26
- "This is a piece of information stored in RiceDB.",
27
- { category: "example", value: 123 }
26
+ "This is a piece of information stored in Rice Storage.",
27
+ { category: "example", value: 123 },
28
28
  );
29
29
 
30
30
  // Search for similar data
31
31
  const results = await client.storage.search("information stored", 1, 5);
32
32
  console.log(results);
33
33
 
34
- // --- State (AI Memory) ---
34
+ // --- State (AI Agent Memory) ---
35
35
  // Focus on a context/task
36
36
  await client.state.focus("User is asking about weather");
37
37
 
@@ -39,9 +39,7 @@ await client.state.focus("User is asking about weather");
39
39
  await client.state.commit(
40
40
  "The user prefers metric units for temperature.",
41
41
  "User preference noted.",
42
- {
43
- source: "conversation",
44
- }
42
+ { source: "conversation" },
45
43
  );
46
44
 
47
45
  // Recall relevant memories
@@ -60,11 +58,11 @@ Control which services are enabled. Useful for applications that only need Stora
60
58
  ```javascript
61
59
  /** @type {import('rice-node-sdk').RiceConfig} */
62
60
  module.exports = {
63
- // Enable/Disable Storage (RiceDB)
61
+ // Enable/Disable Storage
64
62
  storage: {
65
63
  enabled: true, // Set to false if you only use State
66
64
  },
67
- // Enable/Disable State (Memory)
65
+ // Enable/Disable State (AI Agent Memory)
68
66
  state: {
69
67
  enabled: true, // Set to false if you only use Storage
70
68
  },
@@ -76,15 +74,15 @@ module.exports = {
76
74
  Configure connection details and authentication.
77
75
 
78
76
  ```bash
79
- # --- Storage (RiceDB) ---
80
- # URL of your RiceDB instance (default: localhost:50051)
77
+ # --- Storage ---
78
+ # URL of your Storage instance (default: localhost:50051)
81
79
  STORAGE_INSTANCE_URL=localhost:50051
82
80
  # Auth token (if enabled on server)
83
81
  STORAGE_AUTH_TOKEN=my-secret-token
84
82
  # User for auto-login (default: admin)
85
83
  STORAGE_USER=admin
86
84
 
87
- # --- State (Memory) ---
85
+ # --- State (AI Agent Memory) ---
88
86
  # URL of your State instance
89
87
  STATE_INSTANCE_URL=localhost:50051
90
88
  # Auth token
@@ -121,6 +119,153 @@ client.state.setRunId("user-456-session");
121
119
  await client.state.focus("New task for user 456");
122
120
  ```
123
121
 
122
+ ## State Features
123
+
124
+ The State service provides comprehensive AI agent memory and cognition capabilities.
125
+
126
+ ### Core Memory Operations
127
+
128
+ ```typescript
129
+ // Focus - Store in short-term working memory (Flux)
130
+ await client.state.focus("Current task context");
131
+
132
+ // Drift - Read current working memory items
133
+ const driftItems = await client.state.drift();
134
+
135
+ // Commit - Store in long-term episodic memory (Echoes)
136
+ await client.state.commit("User asked about weather", "Provided forecast", {
137
+ action: "weather_lookup",
138
+ agent_id: "assistant",
139
+ });
140
+
141
+ // Reminisce - Recall relevant memories
142
+ const memories = await client.state.reminisce("weather questions", 5);
143
+ ```
144
+
145
+ ### Working Memory (Structured Variables)
146
+
147
+ Store and manage structured state for your agent's reasoning process.
148
+
149
+ ```typescript
150
+ // Set a variable (supports any JSON-serializable value)
151
+ await client.state.setVariable("user_name", "Alice", "explicit");
152
+ await client.state.setVariable(
153
+ "session_context",
154
+ {
155
+ task: "code review",
156
+ language: "TypeScript",
157
+ },
158
+ "system",
159
+ );
160
+
161
+ // Get a variable
162
+ const userVar = await client.state.getVariable("user_name");
163
+ console.log(userVar.value); // "Alice"
164
+
165
+ // List all variables
166
+ const allVars = await client.state.listVariables();
167
+
168
+ // Delete a variable
169
+ await client.state.deleteVariable("user_name");
170
+ ```
171
+
172
+ Variable sources: `"system"`, `"reasoning"`, `"retrieval"`, `"perception"`, `"explicit"`
173
+
174
+ ### Goals
175
+
176
+ Manage hierarchical goals for goal-directed agent behavior.
177
+
178
+ ```typescript
179
+ // Add a goal
180
+ const mainGoal = await client.state.addGoal("Complete project", "high");
181
+
182
+ // Add a sub-goal (with parent)
183
+ const subGoal = await client.state.addGoal(
184
+ "Review authentication module",
185
+ "medium",
186
+ mainGoal.id,
187
+ );
188
+
189
+ // List goals (optionally filter by status)
190
+ const allGoals = await client.state.listGoals();
191
+ const activeGoals = await client.state.listGoals("active");
192
+
193
+ // Update goal status
194
+ await client.state.updateGoal(subGoal.id, "achieved");
195
+ ```
196
+
197
+ Goal priorities: `"low"`, `"medium"`, `"high"`, `"critical"`
198
+ Goal statuses: `"active"`, `"suspended"`, `"achieved"`, `"abandoned"`, `"failed"`
199
+
200
+ ### Concepts (Schema Definitions)
201
+
202
+ Define structured concepts for Level 4 agency and semantic understanding.
203
+
204
+ ```typescript
205
+ // Define a concept with JSON Schema
206
+ await client.state.defineConcept("Task", {
207
+ type: "object",
208
+ properties: {
209
+ id: { type: "string" },
210
+ title: { type: "string" },
211
+ status: { type: "string", enum: ["pending", "in_progress", "completed"] },
212
+ priority: { type: "number", minimum: 1, maximum: 5 },
213
+ },
214
+ required: ["id", "title", "status"],
215
+ });
216
+
217
+ // List defined concepts
218
+ const concepts = await client.state.listConcepts();
219
+ ```
220
+
221
+ ### Actions
222
+
223
+ Log and track agent actions for auditing and learning.
224
+
225
+ ```typescript
226
+ // Submit an action
227
+ const result = await client.state.submitAction("agent-1", "reason", {
228
+ thought: "Analyzing the code structure",
229
+ conclusion: "Start with main entry point",
230
+ });
231
+
232
+ // Get action log
233
+ const actionLog = await client.state.getActionLog(100);
234
+
235
+ // Filter by action type
236
+ const reasonActions = await client.state.getActionLog(50, "reason");
237
+ ```
238
+
239
+ Action types: `"reason"`, `"retrieve"`, `"learn"`, `"ground"`
240
+
241
+ ### Decision Cycles
242
+
243
+ Run autonomous decision cycles with scored action candidates.
244
+
245
+ ```typescript
246
+ // Run a decision cycle with candidates
247
+ const cycleResult = await client.state.runCycle("agent-1", [
248
+ {
249
+ actionType: "reason",
250
+ action: { thought: "Should analyze data first" },
251
+ score: 0.8,
252
+ rationale: "Data analysis is foundational",
253
+ },
254
+ {
255
+ actionType: "retrieve",
256
+ action: { query: "relevant documentation" },
257
+ score: 0.6,
258
+ rationale: "Documentation might help",
259
+ },
260
+ ]);
261
+
262
+ console.log(cycleResult.selectedAction);
263
+ console.log(cycleResult.planningTimeMs);
264
+
265
+ // Get cycle history
266
+ const history = await client.state.getCycleHistory(10);
267
+ ```
268
+
124
269
  ## AI Tool Definitions
125
270
 
126
271
  The SDK provides pre-built tool definitions tailored for popular LLM providers. These tools map directly to State memory operations.
@@ -135,7 +280,7 @@ The SDK provides pre-built tool definitions tailored for popular LLM providers.
135
280
 
136
281
  ```typescript
137
282
  import { state as anthropicTools } from "rice-node-sdk/tools/anthropic";
138
- import { executeTool } from "rice-node-sdk/tools/execute";
283
+ import { execute } from "rice-node-sdk/tools/execute";
139
284
  import { Client } from "rice-node-sdk";
140
285
 
141
286
  const client = new Client();
@@ -150,7 +295,7 @@ const response = await anthropic.messages.create({
150
295
 
151
296
  // 2. Execute tools invoked by the LLM
152
297
  for (const toolUse of response.content.filter((c) => c.type === "tool_use")) {
153
- const result = await executeTool(client.state, toolUse.name, toolUse.input);
298
+ const result = await execute(toolUse.name, toolUse.input, client.state);
154
299
  console.log("Tool result:", result);
155
300
  }
156
301
  ```
@@ -159,7 +304,7 @@ for (const toolUse of response.content.filter((c) => c.type === "tool_use")) {
159
304
 
160
305
  ```typescript
161
306
  import { state as openaiTools } from "rice-node-sdk/tools/openai";
162
- import { executeTool } from "rice-node-sdk/tools/execute";
307
+ import { execute } from "rice-node-sdk/tools/execute";
163
308
  import { Client } from "rice-node-sdk";
164
309
 
165
310
  const client = new Client();
@@ -171,7 +316,7 @@ const response = await openai.chat.completions.create({
171
316
  messages: [
172
317
  /* ... */
173
318
  ],
174
- tools: openaiTools, // Tools are already in OpenAI format
319
+ tools: openaiTools,
175
320
  });
176
321
 
177
322
  // 2. Execute tools
@@ -179,11 +324,7 @@ const toolCalls = response.choices[0].message.tool_calls;
179
324
  if (toolCalls) {
180
325
  for (const toolCall of toolCalls) {
181
326
  const args = JSON.parse(toolCall.function.arguments);
182
- const result = await executeTool(
183
- client.state,
184
- toolCall.function.name,
185
- args
186
- );
327
+ const result = await execute(toolCall.function.name, args, client.state);
187
328
  console.log("Tool result:", result);
188
329
  }
189
330
  }
@@ -193,7 +334,7 @@ if (toolCalls) {
193
334
 
194
335
  ```typescript
195
336
  import { state as googleTools } from "rice-node-sdk/tools/google";
196
- import { executeTool } from "rice-node-sdk/tools/execute";
337
+ import { execute } from "rice-node-sdk/tools/execute";
197
338
  import { Client } from "rice-node-sdk";
198
339
 
199
340
  const client = new Client();
@@ -201,7 +342,7 @@ await client.connect();
201
342
 
202
343
  // 1. Pass tools to Gemini
203
344
  const model = genAI.getGenerativeModel({
204
- model: "gemini-3-flash-preview",
345
+ model: "gemini-2.5-flash",
205
346
  tools: [{ functionDeclarations: googleTools }],
206
347
  });
207
348
 
@@ -211,20 +352,27 @@ const result = await chat.sendMessage("Remember that I like pizza.");
211
352
  const call = result.response.functionCalls()?.[0];
212
353
 
213
354
  if (call) {
214
- const result = await executeTool(client.state, call.name, call.args);
355
+ const result = await execute(call.name, call.args, client.state);
215
356
  console.log("Tool result:", result);
216
357
  }
217
358
  ```
218
359
 
219
360
  ### Tools Included
220
361
 
221
- | Tool | Purpose | SDK Method |
222
- | ---------- | ------------------------------------------------ | -------------------------- |
223
- | `focus` | Store information in short-term working memory | `client.state.focus()` |
224
- | `remember` | Store information in long-term persistent memory | `client.state.commit()` |
225
- | `recall` | Retrieve relevant memories from long-term memory | `client.state.reminisce()` |
226
-
227
- > **Note**: The `remember` tool provided to LLMs maps to the `commit` method in the SDK.
362
+ | Tool | Purpose | SDK Method |
363
+ | ---------------- | ------------------------------------------------ | ------------------------------- |
364
+ | `focus` | Store information in short-term working memory | `client.state.focus()` |
365
+ | `remember` | Store information in long-term persistent memory | `client.state.commit()` |
366
+ | `recall` | Retrieve relevant memories from long-term memory | `client.state.reminisce()` |
367
+ | `setVariable` | Set a structured variable in working memory | `client.state.setVariable()` |
368
+ | `getVariable` | Get a structured variable from working memory | `client.state.getVariable()` |
369
+ | `listVariables` | List all variables in working memory | `client.state.listVariables()` |
370
+ | `deleteVariable` | Delete a variable from working memory | `client.state.deleteVariable()` |
371
+ | `addGoal` | Add a new goal to the agent's goal stack | `client.state.addGoal()` |
372
+ | `updateGoal` | Update the status of an existing goal | `client.state.updateGoal()` |
373
+ | `listGoals` | List all goals, optionally filtered by status | `client.state.listGoals()` |
374
+ | `submitAction` | Submit an action for execution and logging | `client.state.submitAction()` |
375
+ | `getActionLog` | Get the action log for the current run | `client.state.getActionLog()` |
228
376
 
229
377
  ## API Reference
230
378
 
@@ -234,34 +382,84 @@ if (call) {
234
382
  class Client {
235
383
  constructor(options?: { configPath?: string; runId?: string });
236
384
  async connect(): Promise<void>;
237
- get storage(): RiceDBClient;
385
+ get storage(): StorageClient;
238
386
  get state(): StateClient;
239
387
  }
240
388
  ```
241
389
 
242
- ### Storage (RiceDB)
390
+ ### Storage
243
391
 
244
392
  ```typescript
245
- interface RiceDBClient {
246
- insert(id: string, text: string, metadata?: object): Promise<void>;
393
+ interface StorageClient {
394
+ insert(id: string, text: string, metadata?: object): Promise<InsertResult>;
247
395
  search(
248
396
  query: string,
249
397
  limit?: number,
250
- offset?: number
398
+ offset?: number,
251
399
  ): Promise<SearchResult[]>;
252
400
  delete(id: string): Promise<void>;
253
- // ... graph operations
401
+ health(): Promise<string>;
402
+ // ... additional graph operations
254
403
  }
255
404
  ```
256
405
 
257
- ### State (Memory)
406
+ ### State (AI Agent Memory)
258
407
 
259
408
  ```typescript
260
409
  interface StateClient {
261
- focus(content: string): Promise<void>;
262
- commit(input: string, output: string, metadata?: object): Promise<void>;
263
- reminisce(query: string): Promise<string[]>;
410
+ // Core Memory
411
+ focus(content: string): Promise<string>;
412
+ drift(): Promise<any[]>;
413
+ commit(
414
+ input: string,
415
+ output: string,
416
+ options?: CommitOptions,
417
+ ): Promise<boolean>;
418
+ reminisce(query: string, limit?: number): Promise<any[]>;
419
+
420
+ // Working Memory (Variables)
421
+ setVariable(name: string, value: any, source?: string): Promise<boolean>;
422
+ getVariable(name: string): Promise<Variable>;
423
+ listVariables(): Promise<Variable[]>;
424
+ deleteVariable(name: string): Promise<boolean>;
425
+
426
+ // Concepts
427
+ defineConcept(name: string, schema: object): Promise<boolean>;
428
+ listConcepts(): Promise<Concept[]>;
429
+
430
+ // Goals
431
+ addGoal(
432
+ description: string,
433
+ priority?: string,
434
+ parentId?: string,
435
+ ): Promise<Goal>;
436
+ updateGoal(goalId: string, status: string): Promise<boolean>;
437
+ listGoals(statusFilter?: string): Promise<Goal[]>;
438
+
439
+ // Actions
440
+ submitAction(
441
+ agentId: string,
442
+ actionType: string,
443
+ details: any,
444
+ ): Promise<ActionResult>;
445
+ getActionLog(
446
+ limit?: number,
447
+ actionTypeFilter?: string,
448
+ ): Promise<ActionLogEntry[]>;
449
+
450
+ // Decision Cycles
451
+ runCycle(
452
+ agentId: string,
453
+ candidates?: ActionCandidate[],
454
+ ): Promise<CycleResult>;
455
+ getCycleHistory(limit?: number): Promise<CycleResult[]>;
456
+
457
+ // Session Management
264
458
  setRunId(runId: string): void;
459
+ deleteRun(): Promise<boolean>;
460
+
461
+ // Skills
462
+ trigger(skillName: string): Promise<number>;
265
463
  }
266
464
  ```
267
465