You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Docs/README.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,10 +6,10 @@ This folder contains the main project documentation for Agent Memory Toolkit.
6
6
7
7
| Document | Purpose |
8
8
|----------|---------|
9
-
|[concepts.md](concepts.md)| Explains the core memory model, including memory types (turn, summary, fact, user summary), threads, roles, and the processing pipeline. |
10
-
|[local_testing.md](local_testing.md)| Covers local setup, environment configuration, RBAC, Cosmos provisioning, and running the toolkit and Azure Functions locally. |
11
-
|[azure_testing.md](azure_testing.md)| Covers Azure deployment, cloud configuration, required services, and validation steps for running the toolkit in Azure. |
12
-
|[design_patterns.md](design_patterns.md)| Shows when and how to call CRUD operations, summarization, fact extraction, and memory retrieval in chat and multi-agent applications. |
9
+
|[concepts.md](concepts.md)| Explains the core memory model, including memory types (turn, summary, fact, user summary), threads, roles, the processing pipeline, and automatic change feed processing. |
10
+
|[local_testing.md](local_testing.md)| Covers local setup, environment configuration, RBAC, Cosmos provisioning, running the toolkit and Azure Functions locally, and testing change feed auto-processing. |
11
+
|[azure_testing.md](azure_testing.md)| Covers Azure deployment, cloud configuration, required services, change feed settings, and validation steps for running the toolkit in Azure. |
12
+
|[design_patterns.md](design_patterns.md)| Shows when and how to call CRUD operations, summarization, fact extraction, and memory retrieval in chat and multi-agent applications, including automatic processing via the change feed. |
print(results) # Should contain an auto-generated summary
310
+
```
311
+
312
+
Check the Function App logs to confirm the `on_memory_change` trigger fired and the orchestrator completed.
313
+
267
314
### Verify stored results
268
315
269
316
```python
@@ -293,6 +340,8 @@ Common issues:
293
340
| Durable Function starts but fails | Missing app settings or downstream RBAC |
294
341
|`No memories found`| No turn memories exist, or all candidate turns predate the existing summary |
295
342
| Search is slow | Embedding latency, index choice, or region mismatch |
343
+
| Change feed trigger not firing | Verify `COSMOS_DB__accountEndpoint` is set and the function can write to the configured `COSMOS_DB_COUNTERS_CONTAINER` container |
344
+
| Auto-processing not starting | Check threshold settings are > 0 in Function App configuration |
Copy file name to clipboardExpand all lines: Docs/concepts.md
+53Lines changed: 53 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -114,6 +114,59 @@ Prompts for summarization and fact extraction live in `azure_functions/prompts/`
114
114
115
115
---
116
116
117
+
## Automatic Processing (Change Feed)
118
+
119
+
In addition to on-demand processing via the SDK, the toolkit includes a Cosmos DB change feed trigger that **automatically** starts processing orchestrations when enough new turns have been written.
1. The change feed trigger watches the `memories` container for new documents.
137
+
2. Only documents with `type == "turn"` are counted (summaries, facts, and user summaries are ignored).
138
+
3. Documents in the dedicated `counter` container track how many turns have been seen per scope using ETag-based optimistic concurrency.
139
+
4. When a counter crosses a configured threshold, the corresponding Durable Functions orchestration is started automatically.
140
+
141
+
### Threshold settings
142
+
143
+
| Setting | Scope | Default |
144
+
|---------|-------|---------|
145
+
|`THREAD_SUMMARY_EVERY_N`| Per `(user_id, thread_id)`|`0` (disabled) |
146
+
|`FACT_EXTRACTION_EVERY_N`| Per `(user_id, thread_id)`|`0` (disabled) |
147
+
|`USER_SUMMARY_EVERY_N`| Per `user_id` (across all threads) |`0` (disabled) |
148
+
149
+
Set any value to `0` to disable that processing type. For example, setting `THREAD_SUMMARY_EVERY_N=5` generates a thread summary every 5 new turns in each thread.
150
+
151
+
### Required containers
152
+
153
+
| Container | Partition Key | Purpose |
154
+
|-----------|---------------|---------|
155
+
|`memories`|`/user_id`, `/thread_id` (hierarchical) | Existing memory store |
-**End of conversation** — after the user closes a session or a support ticket is resolved.
87
87
-**Long-running thread** — when a thread exceeds a token budget (e.g. > 50 turns) and you need a compact representation for context.
88
88
-**Periodic background job** — on a schedule to keep summaries up to date for active threads.
89
+
-**Automatic (change feed)** — set `THREAD_SUMMARY_EVERY_N` and the change feed trigger handles it. See [Section 8](#8-automatic-processing-with-change-feed).
89
90
90
91
Summaries are incremental: if one already exists for the thread, only newer turns are merged in.
91
92
@@ -111,6 +112,7 @@ The summary is stored automatically in Cosmos with id `summary_user-1_thread-abc
111
112
-**After each meaningful exchange** — extract facts from the latest turns so they are available for retrieval immediately.
112
113
-**End of conversation** — capture all discrete preferences, decisions, and requirements from the thread.
113
114
-**Before a planning step** — in multi-agent workflows, extract facts before handing context to a planner agent.
115
+
-**Automatic (change feed)** — set `FACT_EXTRACTION_EVERY_N` and the change feed trigger handles it. See [Section 8](#8-automatic-processing-with-change-feed).
114
116
115
117
Each fact is stored as its own document with its own embedding, making it ideal for fine-grained semantic search.
116
118
@@ -133,6 +135,7 @@ result = await mem.extract_facts(
133
135
-**Cross-session onboarding** — at the start of a new thread, generate (or update) the user summary so the agent has context from all prior conversations.
134
136
-**After a thread summary is created** — chain it: summarize the thread, then update the user summary.
135
137
-**On a schedule** — for users with many threads, run periodically to keep the profile current.
138
+
-**Automatic (change feed)** — set `USER_SUMMARY_EVERY_N` and the change feed trigger handles it. See [Section 8](#8-automatic-processing-with-change-feed).
136
139
137
140
User summaries are also incremental. The pipeline merges only new thread data into the existing profile.
Instead of calling `generate_thread_summary()`, `extract_facts()`, or `generate_user_summary()` explicitly, you can let the Cosmos DB change feed trigger fire them automatically in the background.
320
+
321
+
### How it works
322
+
323
+
When a new turn is written to the `memories` container, the change feed trigger:
324
+
325
+
1. Increments a counter document in the dedicated `counter` container for each relevant scope.
326
+
2. Checks whether the counter has crossed a configured threshold.
327
+
3. Starts the appropriate Durable Functions orchestration if the threshold is crossed.
328
+
329
+
### Configuration
330
+
331
+
Set these application settings (in `local.settings.json` locally or Function App settings in Azure):
332
+
333
+
| Setting | Scope | Effect |
334
+
|---------|-------|--------|
335
+
|`THREAD_SUMMARY_EVERY_N=5`| Per `(user_id, thread_id)`| Summarize the thread every 5 turns |
336
+
|`FACT_EXTRACTION_EVERY_N=3`| Per `(user_id, thread_id)`| Extract facts every 3 turns |
337
+
|`USER_SUMMARY_EVERY_N=10`| Per `user_id`| Update user profile every 10 turns across all threads |
338
+
339
+
Set any value to `0` to disable that processing type. All three default to `0` (disabled).
340
+
341
+
### Required infrastructure
342
+
343
+
The change feed trigger needs two additional Cosmos DB containers beyond the existing `memories` container:
344
+
345
+
-**`counter`** — stores lightweight per-thread and per-user message counters used for threshold checks
346
+
-**`leases`** — auto-created by the Azure Functions runtime for change feed checkpointing
347
+
348
+
The `COSMOS_DB__accountEndpoint` setting must also be configured for the identity-based change feed binding.
349
+
350
+
### When to use automatic vs. on-demand
351
+
352
+
| Approach | Best for |
353
+
|----------|----------|
354
+
|**On-demand**| Full control, testing, one-off processing, chaining operations |
355
+
|**Automatic**| Always-on background processing, fire-and-forget, production workloads |
356
+
357
+
Both approaches use the same orchestrator and activities, so the output is identical.
0 commit comments