feat: add emit-raw-events and emit-raw-event-data metadata flags - #1385
Open
mxmzb wants to merge 3 commits into
Open
feat: add emit-raw-events and emit-raw-event-data metadata flags#1385mxmzb wants to merge 3 commits into
mxmzb wants to merge 3 commits into
Conversation
Add two new metadata flags to control RAW event emission and raw_event field population in the LangGraph agent (Python + TypeScript): - emit-raw-events (default: true): gates whether RawEvent objects are yielded during streaming. When false, RAW events are suppressed. - emit-raw-event-data (default: true): controls whether the raw_event field is populated on non-RAW events (StateSnapshot, TextMessage, ToolCall, etc.). When false, raw_event is stripped before serialization. Both flags follow the existing emit-messages / emit-tool-calls metadata pattern and are read per-event from LangGraph stream event metadata. Combined, these flags can reduce SSE stream payload by up to ~94% (from ~6.5MB to ~420KB per turn) for agents with large tool responses. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Python Preview PackagesVersion
Install with uvAdd the TestPyPI index to your [[tool.uv.index]]
name = "testpypi"
url = "https://test.pypi.org/simple/"
explicit = trueThen install the packages you need: # Core SDK
uv add 'ag-ui-protocol==0.0.0.dev1774582043' --index testpypi
# Integrations (each already depends on the matching ag-ui-protocol preview)
uv add 'ag-ui-langgraph==0.0.0.dev1774582043' --index testpypi
uv add 'ag-ui-crewai==0.0.0.dev1774582043' --index testpypi
# NOTE: ag-ui-agent-spec depends on pyagentspec (git-only, not on PyPI).
# You will need to install pyagentspec separately from its git repo.
uv add 'ag-ui-agent-spec==0.0.0.dev1774582043' --index testpypi
uv add 'ag_ui_adk==0.0.0.dev1774582043' --index testpypi
uv add 'ag_ui_strands==0.0.0.dev1774582043' --index testpypiInstall with pippip install \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple/ \
ag-ui-protocol==0.0.0.dev1774582043
Commit: f6901d5 |
@ag-ui/a2a-middleware
@ag-ui/a2ui-middleware
@ag-ui/mcp-apps-middleware
@ag-ui/middleware-starter
@ag-ui/a2a
@ag-ui/adk
@ag-ui/ag2
@ag-ui/agno
@ag-ui/aws-strands
@ag-ui/claude-agent-sdk
@ag-ui/crewai
@ag-ui/langchain
@ag-ui/langgraph
@ag-ui/langroid
@ag-ui/llamaindex
@ag-ui/mastra
@ag-ui/pydantic-ai
@ag-ui/server-starter
@ag-ui/server-starter-all-features
@ag-ui/vercel-ai-sdk
create-ag-ui-app
@ag-ui/client
@ag-ui/core
@ag-ui/encoder
@ag-ui/proto
commit: |
…ta is False The Python _dispatch_event was storing the emit_raw_event_data flag but never reading it to strip raw_event from non-RAW events. This caused emit_raw_event_data=False to be silently ignored, unlike the TypeScript implementation which correctly strips rawEvent. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…coercion
- Make emit_raw_event_data per-event (not sticky across nodes) to match
emit_raw_events behavior — flags now reset to true for events that
don't set them, enabling correct per-node control
- Move metadata flag reads before typed event dispatch so STATE_SNAPSHOT
events use the correct value for the current iteration
- Fix metadata None crash: use (event.get("metadata") or {}) to handle
metadata key present but set to None
- Add bool() / Boolean() coercion at reading sites to prevent string
"false" from being treated as truthy
- Replace delete event.rawEvent with = undefined for safer mutation
- Add emit_raw_event_data to Python RunMetadata TypedDict for type safety
- Add per-event non-sticky behavior test
- Refactor TS tests to use shared simulateRawEventDispatch helper
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was referenced Apr 2, 2026
|
I implemented the dotnet variant: #2298 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
emit-raw-eventsmetadata flag (defaulttrue) to gateRawEventemission — whenfalse, RAW events are suppressed entirelyemit-raw-event-datametadata flag (defaulttrue) to control whether theraw_eventfield is populated on non-RAW events (StateSnapshot, TextMessage, ToolCall, etc.) — whenfalse,raw_eventis stripped before serializationemit-messages/emit-tool-callsmetadata pattern and are read per-event from LangGraph stream event metadataagent.py) and TypeScript (agent.ts) LangGraph integrationsContext
ag_ui_langgraphcan inflate SSE streams from ~420KB to ~6.5MB per turn due to unconditional RAW event emission (~4.4MB) andraw_eventfield duplication on StateSnapshot events (~1.6MB). These two flags enable ~94% payload reduction with no visible frontend impact.Companion PR: CopilotKit/CopilotKit — exposes these flags via
copilotkit_customize_config()/copilotkitCustomizeConfig().Usage
Via metadata (direct):
Via CopilotKit SDK (companion PR):
Test plan
python -m pytest integrations/langgraph/python/tests/test_emit_raw_events.py -v(11 tests)npx vitest run integrations/langgraph/typescript/src/emit-raw-events.test.ts(7 tests)raw_eventstripped from network tab🤖 Generated with Claude Code