Skip to content

feat: add emit-raw-events and emit-raw-event-data metadata flags - #1385

Open
mxmzb wants to merge 3 commits into
mainfrom
feat/emit-raw-events-config
Open

feat: add emit-raw-events and emit-raw-event-data metadata flags#1385
mxmzb wants to merge 3 commits into
mainfrom
feat/emit-raw-events-config

Conversation

@mxmzb

@mxmzb mxmzb commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add emit-raw-events metadata flag (default true) to gate RawEvent emission — when false, RAW events are suppressed entirely
  • Add emit-raw-event-data metadata flag (default true) to control 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
  • Implemented in both Python (agent.py) and TypeScript (agent.ts) LangGraph integrations

Context

ag_ui_langgraph can inflate SSE streams from ~420KB to ~6.5MB per turn due to unconditional RAW event emission (~4.4MB) and raw_event field 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):

config = {"metadata": {"emit-raw-events": False, "emit-raw-event-data": False}}

Via CopilotKit SDK (companion PR):

config = copilotkit_customize_config(config, emit_raw_events=False, emit_raw_event_data=False)

Test plan

  • Python: python -m pytest integrations/langgraph/python/tests/test_emit_raw_events.py -v (11 tests)
  • TypeScript: npx vitest run integrations/langgraph/typescript/src/emit-raw-events.test.ts (7 tests)
  • Regression: existing tests pass in both Python and TypeScript
  • Manual: run a LangGraph agent with metadata flags set, verify RAW events suppressed and raw_event stripped from network tab

🤖 Generated with Claude Code

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>
@mxmzb
mxmzb requested a review from a team as a code owner March 27, 2026 01:34
@vercel

vercel Bot commented Mar 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ag-ui-dojo Ready Ready Preview, Comment Mar 27, 2026 3:30am

Request Review

@github-actions

github-actions Bot commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Python Preview Packages

Version 0.0.0.dev1774582043 published to TestPyPI.

Warning: These packages are built from contributor code that may not yet have been vetted for correctness or security. Install at your own risk and do not use in production.

Install with uv

Add the TestPyPI index to your pyproject.toml:

[[tool.uv.index]]
name = "testpypi"
url = "https://test.pypi.org/simple/"
explicit = true

Then 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 testpypi

Install with pip

pip install \
  --index-url https://test.pypi.org/simple/ \
  --extra-index-url https://pypi.org/simple/ \
  ag-ui-protocol==0.0.0.dev1774582043

Use --extra-index-url https://pypi.org/simple/ so pip can resolve
transitive dependencies (pydantic, fastapi, etc.) from real PyPI.


Commit: f6901d5

@pkg-pr-new

pkg-pr-new Bot commented Mar 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

@ag-ui/a2a-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/a2a-middleware@1385

@ag-ui/a2ui-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/a2ui-middleware@1385

@ag-ui/mcp-apps-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/mcp-apps-middleware@1385

@ag-ui/middleware-starter

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/middleware-starter@1385

@ag-ui/a2a

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/a2a@1385

@ag-ui/adk

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/adk@1385

@ag-ui/ag2

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/ag2@1385

@ag-ui/agno

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/agno@1385

@ag-ui/aws-strands

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/aws-strands@1385

@ag-ui/claude-agent-sdk

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/claude-agent-sdk@1385

@ag-ui/crewai

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/crewai@1385

@ag-ui/langchain

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/langchain@1385

@ag-ui/langgraph

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/langgraph@1385

@ag-ui/langroid

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/langroid@1385

@ag-ui/llamaindex

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/llamaindex@1385

@ag-ui/mastra

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/mastra@1385

@ag-ui/pydantic-ai

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/pydantic-ai@1385

@ag-ui/server-starter

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/server-starter@1385

@ag-ui/server-starter-all-features

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/server-starter-all-features@1385

@ag-ui/vercel-ai-sdk

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/vercel-ai-sdk@1385

create-ag-ui-app

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/create-ag-ui-app@1385

@ag-ui/client

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/client@1385

@ag-ui/core

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/core@1385

@ag-ui/encoder

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/encoder@1385

@ag-ui/proto

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/proto@1385

commit: fee2619

…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>
@halllo

halllo commented Aug 2, 2026

Copy link
Copy Markdown

I implemented the dotnet variant: #2298

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants