docs: add wire-safe serialization section for TypeScript streaming events#693
Conversation
…ents
Document the toJSON() serialization behavior for all TypeScript streaming
events. This includes:
- New 'Wire-Safe Serialization' section in the streaming overview
- Table showing what each event serializes to
- Explanation of excluded fields (agent, tool, cancel, retry)
- Error handling format ({ error: { message?: string } })
- In-process vs wire access patterns
- Updated Express.js example with serialization comments
Related: strands-agents/sdk-typescript#708
|
|
||
| ## Wire-Safe Serialization (TypeScript) | ||
|
|
||
| When streaming events over the wire (SSE, WebSockets, HTTP responses), each event in TypeScript carries a reference to the full `Agent` instance — including conversation history, app state, model configuration, and internal registries. Calling `JSON.stringify(event)` without serialization control would produce massively bloated output that grows with conversation length. |
There was a problem hiding this comment.
@agent-of-mkmeral this is too long. we don't have to explain everything (internals etc). look at other docs. we should explain that during serialization, we remove some fields. they can directly programmatically access.
also keep the events, so customers can see what we actually export/where
There was a problem hiding this comment.
Thanks for the feedback! Pushed a fix in 994c75f — condensed the section significantly:
- Removed the verbose "How It Works", "Excluded Fields", "Error Handling", and "In-Process Access" subsections
- Now a single concise paragraph explaining that
agent,tool,cancel,retryare excluded during serialization and are still available for direct programmatic access - Kept the events table so customers can see what each event serializes to
Went from ~73 lines → ~30 lines. Let me know if it needs further trimming.
There was a problem hiding this comment.
Follow-up push in 0a332ee addressing the remaining feedback on this thread (serialization framing + TS tab). Should be good now — please take another look when you get a chance.
- Remove verbose 'How It Works', 'Excluded Fields', 'Error Handling', and 'In-Process Access' subsections - Keep single concise paragraph explaining serialization behavior - Retain events table showing what each event serializes to - Mention excluded fields (agent, tool, cancel, retry) inline Co-authored-by: mkmeral <mkmeral@users.noreply.github.com>
Documentation Preview ReadyYour documentation preview has been successfully deployed! Preview URL: https://d3ehv1nix5p99z.cloudfront.net/pr-cms-693/docs/user-guide/quickstart/overview/ Updated at: 2026-03-21T00:32:21.621Z |
|
|
||
| ## Wire-Safe Serialization (TypeScript) | ||
|
|
||
| When streaming events over the wire (SSE, WebSockets, HTTP responses), TypeScript events are automatically serialized to compact JSON. Fields like `agent`, `tool`, `cancel`, and `retry` are excluded from serialization since they contain large internal references or mutable control flags — these fields are still available for direct programmatic access in-process. |
There was a problem hiding this comment.
talk less about wire, more about serialization. (e..g when streaming events are serialized ...).
also dont talk about what we exclude but what we keep. (you can also mention the rest ofc). Essentially this behavior enables below
There was a problem hiding this comment.
Done in 0a332ee:
- Renamed section to "Event Serialization" (dropped "wire-safe" language)
- Reframed the opening to lead with what each event keeps: "each event keeps its
typediscriminator along with the relevant data fields" - The serialized fields table comes first — showing customers exactly what they get
- Excluded fields (
agent,tool,cancel,retry) moved to a brief note after the table
| </Tab> | ||
| </Tabs> | ||
|
|
||
| ## Wire-Safe Serialization (TypeScript) |
There was a problem hiding this comment.
this whole section should be in TS tab
There was a problem hiding this comment.
Done — the whole section is now wrapped in <Tabs> with:
- Python tab: brief note that events are dicts and serialize directly with
json.dumps() - TypeScript tab: the full serialization table + code example
…fields Address review feedback: - Rename 'Wire-Safe Serialization (TypeScript)' to 'Event Serialization' - Wrap in <Tabs> with Python/TypeScript tabs - Lead with what each event keeps during serialization - Move excluded fields mention to secondary position after table - Use 'serialization' language instead of 'wire-safe'
|
add this under streaming events tabs (that already exist) or something, I don't want a tab for python. also that python info is not correct anyway |
…nt types Address review feedback from @mkmeral: - Remove Tabs wrapper and Python tab (info was not correct) - Downgrade to ### subsection under Event Types (same level as Lifecycle Events, Model Stream Events, etc.) - TypeScript serialization content stays as-is, directly under heading
|
Done in
Net change: -11 lines, +1 line. |
Description
Documents the
toJSON()serialization behavior for all TypeScript streaming events. When events are sent over the wire (SSE, WebSockets, HTTP responses), thetoJSON()method ensures compact output (~100-200 bytes) instead of serializing the entireAgentinstance (~54KB+ per event).Changes
Streaming Overview (
index.mdx): Added new "Wire-Safe Serialization (TypeScript)" section with:toJSON()works withJSON.stringify()agent,tool,cancel,retry){ error: { message?: string } })Express.js example (
async-iterators.ts): Added comments explaining the automatic wire-safe serialization behaviorRelated Issues
toJSON()to all streaming eventsType of Change
Checklist
npm run dev