@hotmeshio/hotmesh 0.5.2 → 0.5.3
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 +30 -45
- package/build/package.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -106,9 +106,9 @@ This index improves performance for filtered queries while reducing index size.
|
|
|
106
106
|
|
|
107
107
|
## Durable AI Agents
|
|
108
108
|
|
|
109
|
-
Agents often require memory—context that persists between invocations, spans multiple perspectives, or outlives a single process.
|
|
109
|
+
Agents often require memory—context that persists between invocations, spans multiple perspectives, or outlives a single process.
|
|
110
110
|
|
|
111
|
-
The following example builds a "research agent" that
|
|
111
|
+
The following example builds a "research agent" that executes hooks with different perspectives and then synthesizes. The data-first approach sets up initial state and then uses temporary hook functions to augment over the lifecycle of the entity record.
|
|
112
112
|
|
|
113
113
|
### Research Agent Example
|
|
114
114
|
|
|
@@ -116,56 +116,57 @@ The following example builds a "research agent" that runs sub-flows and self-ref
|
|
|
116
116
|
|
|
117
117
|
```ts
|
|
118
118
|
export async function researchAgent(query: string): Promise<any> {
|
|
119
|
-
const
|
|
119
|
+
const agent = await MemFlow.workflow.entity();
|
|
120
120
|
|
|
121
121
|
// Set up shared memory for this agent session
|
|
122
|
-
|
|
122
|
+
const initialState = {
|
|
123
123
|
query,
|
|
124
124
|
findings: [],
|
|
125
125
|
perspectives: {},
|
|
126
126
|
confidence: 0,
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
verification: {},
|
|
128
|
+
status: 'researching',
|
|
129
|
+
startTime: new Date().toISOString(),
|
|
130
|
+
}
|
|
131
|
+
await agent.set<typeof initialState>(initialState);
|
|
129
132
|
|
|
130
|
-
// Launch perspective hooks in parallel
|
|
131
|
-
|
|
133
|
+
// Launch perspective hooks in parallel
|
|
134
|
+
await MemFlow.workflow.execHook({
|
|
132
135
|
taskQueue: 'agents',
|
|
133
136
|
workflowName: 'optimisticPerspective',
|
|
134
|
-
args: [query]
|
|
137
|
+
args: [query],
|
|
138
|
+
signalId: 'optimistic-complete'
|
|
135
139
|
});
|
|
136
140
|
|
|
137
|
-
|
|
141
|
+
await MemFlow.workflow.execHook({
|
|
138
142
|
taskQueue: 'agents',
|
|
139
143
|
workflowName: 'skepticalPerspective',
|
|
140
|
-
args: [query]
|
|
144
|
+
args: [query],
|
|
145
|
+
signalId: 'skeptical-complete'
|
|
141
146
|
});
|
|
142
147
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
workflowName: 'factCheckAgent',
|
|
147
|
-
workflowId: `fact-check-${Date.now()}`,
|
|
148
|
+
await MemFlow.workflow.execHook({
|
|
149
|
+
taskQueue: 'agents',
|
|
150
|
+
workflowName: 'verificationHook',
|
|
148
151
|
args: [query],
|
|
149
|
-
|
|
152
|
+
signalId: 'verification-complete'
|
|
150
153
|
});
|
|
151
154
|
|
|
152
|
-
// Wait for all views to complete before analyzing
|
|
153
|
-
await Promise.all([optimistic, skeptical, factChecker]);
|
|
154
|
-
|
|
155
|
-
// Final synthesis: aggregate and compare all perspectives
|
|
156
155
|
await MemFlow.workflow.execHook({
|
|
157
156
|
taskQueue: 'perspectives',
|
|
158
157
|
workflowName: 'synthesizePerspectives',
|
|
159
|
-
args: []
|
|
158
|
+
args: [],
|
|
159
|
+
signalId: 'synthesis-complete',
|
|
160
160
|
});
|
|
161
161
|
|
|
162
|
-
return
|
|
162
|
+
// return analysis, verification, and synthesis
|
|
163
|
+
return await agent.get();
|
|
163
164
|
}
|
|
164
165
|
```
|
|
165
166
|
|
|
166
|
-
> 💡
|
|
167
|
+
> 💡 A complete implementation of this Research Agent example with tests, OpenAI integration, and multi-perspective analysis can be found in the [agent test suite](https://github.com/hotmeshio/sdk-typescript/tree/main/tests/memflow/agent).
|
|
167
168
|
|
|
168
|
-
#### Hooks
|
|
169
|
+
#### Perspective Hooks
|
|
169
170
|
|
|
170
171
|
```ts
|
|
171
172
|
// Optimistic hook looks for affirming evidence
|
|
@@ -184,27 +185,11 @@ export async function skepticalPerspective(query: string, config: {signal: strin
|
|
|
184
185
|
await entity.merge({ perspectives: { skeptical: { counterEvidence, confidence: 0.6 }}});
|
|
185
186
|
await MemFlow.workflow.signal(config.signal, {});
|
|
186
187
|
}
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
#### Child Agent: Fact Checker
|
|
190
|
-
|
|
191
|
-
```ts
|
|
192
|
-
// A dedicated child agent with its own entity type and context
|
|
193
|
-
export async function factCheckAgent(query: string): Promise<any> {
|
|
194
|
-
const entity = await MemFlow.workflow.entity();
|
|
195
|
-
await entity.set({ query, sources: [], verifications: [] });
|
|
196
188
|
|
|
197
|
-
|
|
198
|
-
taskQueue: 'agents',
|
|
199
|
-
workflowName: 'verifySourceCredibility',
|
|
200
|
-
args: [query]
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
return await entity.get();
|
|
204
|
-
}
|
|
189
|
+
// Other hooks...
|
|
205
190
|
```
|
|
206
191
|
|
|
207
|
-
#### Synthesis
|
|
192
|
+
#### Synthesis Hook
|
|
208
193
|
|
|
209
194
|
```ts
|
|
210
195
|
// Synthesis hook aggregates different viewpoints
|
|
@@ -231,7 +216,7 @@ export async function synthesizePerspectives(config: {signal: string}): Promise<
|
|
|
231
216
|
|
|
232
217
|
## Building Pipelines with State
|
|
233
218
|
|
|
234
|
-
HotMesh treats pipelines as long-lived records
|
|
219
|
+
HotMesh treats pipelines as long-lived records. Every pipeline run is stateful, resumable, and traceable.
|
|
235
220
|
|
|
236
221
|
### Setup a Data Pipeline
|
|
237
222
|
|
|
@@ -357,7 +342,7 @@ export async function triggerRefresh() {
|
|
|
357
342
|
}
|
|
358
343
|
```
|
|
359
344
|
|
|
360
|
-
> 💡
|
|
345
|
+
> 💡 A complete implementation of this Pipeline example with OpenAI Vision integration, processing hooks, and document workflow automation can be found in the [pipeline test suite](https://github.com/hotmeshio/sdk-typescript/tree/main/tests/memflow/pipeline).
|
|
361
346
|
|
|
362
347
|
---
|
|
363
348
|
|
package/build/package.json
CHANGED