@agent-diaries/core 0.1.4 → 0.1.41

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 (2) hide show
  1. package/README.md +37 -7
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -69,6 +69,35 @@ async function runAgent() {
69
69
 
70
70
  runAgent();
71
71
  ```
72
+ ### Forcefully Re-running a Task (The Engineering Trick)
73
+
74
+ If you want an agent to strictly avoid duplicate work, use `await diary.claimTask(task)`. It will automatically return `false` if it was done.
75
+
76
+ But if an agent wants to explicitly overwrite or re-do a task because the user demanded it, you skip `claimTask()` entirely and just write the final result using `await diary.writeTaskResult(task, newResult)`. This seamlessly replaces the old memory with the new one.
77
+
78
+ ```text
79
+ 🤖 Agent Alice: Claiming and performing 'Generate Monthly Report'...
80
+ -> Task done! Saving result.
81
+ --------------------------------------------------
82
+ 🤖 Agent Bob: Checking if 'Generate Monthly Report' is done...
83
+ -> 🛑 Found in Diary! Previous result: "Report for May: $12,000 Revenue."
84
+ -> 💬 Informs User: "This report was already generated. Do you want me to re-run it with the latest data?"
85
+ -> 👤 User responds: YES
86
+ -> Agent Bob forcefully re-running the task...
87
+ ```
88
+
89
+ ```typescript
90
+ // 1. Check if it's already done (for logging/informing user)
91
+ if (await diary.hasProcessedTask(currentTask)) {
92
+ console.log("Task is already done. Forcefully re-running per user request...");
93
+ }
94
+
95
+ // 2. Perform the work again
96
+ const updatedResult = "Found 0 warnings, ALL critical errors resolved.";
97
+
98
+ // 3. Skip claimTask() and directly overwrite the old memory
99
+ await diary.writeTaskResult(currentTask, updatedResult);
100
+ ```
72
101
 
73
102
  ## ☁️ Cloud Storage Adapters (Production)
74
103
 
@@ -88,20 +117,21 @@ const diary = new AgentDiary({
88
117
  });
89
118
  ```
90
119
 
91
- ### PostgreSQL (Best for Stateful Architectures)
92
- The `PostgresStorage` adapter natively uses `pg_advisory_lock` to ensure absolute row-level safety during concurrent task evaluation.
120
+ ### MongoDB (Best for Document Scaling)
121
+ The `MongoStorage` adapter natively uses atomic `_id` unique insertion constraints to guarantee row-level safety during concurrent task evaluation, with built-in TTL lock expiration.
93
122
 
94
123
  ```typescript
95
124
  import { AgentDiary } from '@agent-diaries/core';
96
- import { PostgresStorage } from '@agent-diaries/core/dist/adapters/postgres';
97
- import { Pool } from 'pg';
125
+ import { MongoStorage } from '@agent-diaries/core/dist/adapters/mongo';
126
+ import { MongoClient } from 'mongodb';
98
127
 
99
- const pgStorage = new PostgresStorage({ pool: new Pool({ connectionString: process.env.DATABASE_URL }) });
100
- await pgStorage.initialize(); // Creates the state table
128
+ const client = new MongoClient(process.env.MONGO_URI);
129
+ await client.connect();
130
+ const collection = client.db('agent_diaries').collection('tasks');
101
131
 
102
132
  const diary = new AgentDiary({
103
133
  agentId: 'db-bot',
104
- storage: pgStorage
134
+ storage: new MongoStorage({ collection })
105
135
  });
106
136
  ```
107
137
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-diaries/core",
3
- "version": "0.1.4",
3
+ "version": "0.1.41",
4
4
  "description": "The lightweight, framework-agnostic memory layer for edge AI agents.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",