Skip to content

Commit c96e84d

Browse files
authored
deepagents: add tip for filtering out summarization tokens (#3586)
1 parent fa83223 commit c96e84d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/oss/deepagents/context-engineering.mdx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,44 @@ This dual approach ensures the agent maintains awareness of its goals and progre
348348
- If any model call raises a standard @[ContextOverflowError], Deep Agents immediately falls back to summarization and retries with summary + recent preserved messages
349349
- Older messages are summarized by the model
350350

351+
:::python
352+
<Tip>
353+
[Streaming tokens](/oss/deepagents/streaming#llm-tokens) from the agent will generally include tokens generated by the summarization step. You can filter out these tokens using their associated metadata:
354+
```python
355+
for chunk in agent.stream(
356+
{"messages": [...]},
357+
stream_mode="messages",
358+
version="v2",
359+
):
360+
token, metadata = chunk["data"]
361+
if metadata.get("lc_source") == "summarization": # [!code highlight]
362+
continue
363+
else:
364+
...
365+
```
366+
</Tip>
367+
:::
368+
369+
:::js
370+
<Tip>
371+
[Streaming tokens](/oss/deepagents/streaming#llm-tokens) from the agent will generally include tokens generated by the summarization step. You can filter out these tokens using their associated metadata:
372+
```typescript
373+
for await (const [namespace, chunk] of await agent.stream(
374+
{ messages: [...] },
375+
{ streamMode: "messages" },
376+
)) {
377+
const [message, metadata] = chunk;
378+
if (metadata?.lcSource === "summarization") { // [!code highlight]
379+
continue;
380+
} else {
381+
...
382+
}
383+
}
384+
```
385+
</Tip>
386+
:::
387+
388+
351389
:::python
352390

353391
##### Summarization Tool

0 commit comments

Comments
 (0)