effect-assistant 0.8.2 → 0.8.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.
Files changed (2) hide show
  1. package/README.md +84 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -180,6 +180,90 @@ reads the last summary plus what came after; the log keeps everything, so the us
180
180
  turn.run({ instructions, history: Compaction.since(Schema.is(Summary)) })
181
181
  ```
182
182
 
183
+ ### Putting it together
184
+
185
+ One assistant with all of it: tools with an approval, a skill, memory, blocks that show a tool's result, a specialist,
186
+ a daily budget, and a summary after the reply once the chat is long. The budget and the summarizing are services of
187
+ your app; the handler decides what they mean for the chat. `MyTools` holds a `search_documents` tool and a
188
+ `send_email` tool with `needsApproval`; `ChooseOne` is a block, `WeeklyReport` a [skill](https://github.com/dbrxnds/effect-assistant/tree/main/apps/docs/guide/skills.md) and
189
+ `Research` a [specialist](https://github.com/dbrxnds/effect-assistant/tree/main/apps/docs/guide/specialists.md).
190
+
191
+ ```ts
192
+ class Summary extends Schema.TaggedClass<Summary>()("Summary", { text: Schema.String, throughSequence: Schema.Int }) {}
193
+ class BudgetReached extends Schema.TaggedClass<BudgetReached>()("BudgetReached", {}) {}
194
+
195
+ type MyEvent = Summary | BudgetReached
196
+
197
+ export const MyAssistant = Assistant.make("my-assistant", {
198
+ blocks: BlockKit.make([ChooseOne, Block.fromToolResult(SearchDocuments)]),
199
+ events: [Summary, BudgetReached],
200
+ specialists: [Research]
201
+ })
202
+
203
+ class AiBudget extends Context.Service<
204
+ AiBudget,
205
+ { readonly exceeded: (chatId: ChatId.ChatId) => Effect.Effect<boolean> }
206
+ >()("AiBudget") {}
207
+
208
+ class ChatCompaction extends Context.Service<
209
+ ChatCompaction,
210
+ {
211
+ readonly summarize: (
212
+ chat: Assistant.Chat<MyEvent>,
213
+ turn: Assistant.Turn<MyEvent>
214
+ ) => Effect.Effect<Option.Option<Summary>, AiError.AiError>
215
+ }
216
+ >()("ChatCompaction") {}
217
+
218
+ const Skills = Skill.toolkit([WeeklyReport])
219
+
220
+ export const MyAssistantLive = MyAssistant.toLayer(
221
+ Effect.gen(function* () {
222
+ const budget = yield* AiBudget
223
+ const compaction = yield* ChatCompaction
224
+ const memory = yield* Memory.MemoryStore
225
+
226
+ return Effect.fn("MyAssistant.turn")(function* (turn: Assistant.Turn<MyEvent>) {
227
+ const chat = yield* MyAssistant.Chat
228
+
229
+ if (yield* budget.exceeded(turn.chatId)) {
230
+ yield* chat.append(BudgetReached.make({}))
231
+
232
+ return Stream.empty
233
+ }
234
+
235
+ // After the reply, so the user doesn't wait; a failed summary leaves the chat as it is.
236
+ const summarized = compaction.summarize(chat, turn).pipe(
237
+ Effect.flatMap(Option.match({ onNone: () => Effect.void, onSome: (summary) => chat.append(summary) })),
238
+ Effect.catchCause((cause) => Effect.logWarning("compaction failed", cause))
239
+ )
240
+
241
+ return turn
242
+ .run({
243
+ instructions: `${instructions}\n\n${Memory.render(yield* memory.facts(turn.chatId))}`,
244
+ toolkit: Toolkit.merge(MyTools, Memory.Tools, Skills),
245
+ history: Compaction.since(Schema.is(Summary)),
246
+ maxSteps: 20
247
+ })
248
+ .pipe(
249
+ Stream.concat(Stream.drain(Stream.fromEffect(summarized))),
250
+ Stream.provideService(Memory.MemoryStore, memory)
251
+ )
252
+ })
253
+ })
254
+ ).pipe(Layer.provide([MyToolsLive, Memory.layerTools, Skills.layer, ResearchLive]))
255
+ ```
256
+
257
+ ```text
258
+ AiBudget.exceeded ─► BudgetReached ─► chat log (and no turn)
259
+ chat log ─► Compaction.since(Summary) ─► history ──┐
260
+ memory facts ─► instructions ──────────────────────┼─► turn.run ─► events ─► chat log
261
+ MyTools + Memory.Tools + Skills ─► toolkit ────────┘
262
+ ChatCompaction.summarize, after the reply ─► Summary ─► chat log
263
+ ```
264
+
265
+ The app provides `AiBudget`, `ChatCompaction` and a `Memory.MemoryStore`.
266
+
183
267
  ### And more
184
268
 
185
269
  - [Specialists](https://github.com/dbrxnds/effect-assistant/tree/main/apps/docs/guide/specialists.md): focused agents that do slow work in the background.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-assistant",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "A colleague assistant on Effect: an append-only event log per chat, an interruptible agent loop, specialists, skills, and UI blocks",
5
5
  "license": "MIT",
6
6
  "repository": {