Skip to content

feat: add notificationThrottleMs and notificationMinChunkSize to AbstractAgent - #1420

Closed
mxmzb wants to merge 4 commits into
mainfrom
feat/notification-throttle-ms
Closed

feat: add notificationThrottleMs and notificationMinChunkSize to AbstractAgent#1420
mxmzb wants to merge 4 commits into
mainfrom
feat/notification-throttle-ms

Conversation

@mxmzb

@mxmzb mxmzb commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds two optional throttle knobs to AbstractAgent that coalesce rapid subscriber notifications during streaming
  • notificationThrottleMs: time-based cap (e.g. 16 = ~60fps)
  • notificationMinChunkSize: character-based cap (e.g. 20 = batch single-char tokens until 20 chars accumulate)
  • When both are set, notification fires when either threshold is hit first
  • Mutations are always applied immediately (agent.messages/agent.state stay current); only subscriber notifications are throttled
  • Default path (no throttle) is the original code, unchanged. Throttle logic lives in a separate private method

Test plan

  • Default behavior: every mutation fires onMessagesChanged (1:1)
  • notificationThrottleMs: fewer notifications than chunks, final state complete
  • notificationMinChunkSize: holds notifications until N chars accumulate, final state complete
  • All 355 existing tests pass

🤖 Generated with Claude Code

@mxmzb
mxmzb requested a review from a team as a code owner April 2, 2026 12:30
@vercel

vercel Bot commented Apr 2, 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 Apr 2, 2026 4:10pm

Request Review

@pkg-pr-new

pkg-pr-new Bot commented Apr 2, 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@1420

@ag-ui/a2ui-middleware

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

@ag-ui/mcp-apps-middleware

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

@ag-ui/middleware-starter

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

@ag-ui/a2a

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

@ag-ui/adk

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

@ag-ui/ag2

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

@ag-ui/agno

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

@ag-ui/aws-strands

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

@ag-ui/claude-agent-sdk

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

@ag-ui/crewai

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

@ag-ui/langchain

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

@ag-ui/langgraph

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

@ag-ui/langroid

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

@ag-ui/llamaindex

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

@ag-ui/mastra

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

@ag-ui/pydantic-ai

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

@ag-ui/server-starter

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

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

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

@ag-ui/vercel-ai-sdk

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

create-ag-ui-app

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

@ag-ui/client

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

@ag-ui/core

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

@ag-ui/encoder

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

@ag-ui/proto

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

commit: e13b9f1

…ractAgent

Adds two optional throttle knobs to AbstractAgent that coalesce rapid
subscriber notifications during streaming:

- notificationThrottleMs: time-based cap (e.g. 16ms = ~60fps)
- notificationMinChunkSize: character-based cap (e.g. 20 = batch
  single-char tokens until 20 chars accumulate)

When both are set, notification fires when EITHER threshold is hit first.
Mutations are always applied immediately (agent.messages stays current);
only subscriber notifications are throttled.

Default path (no throttle) is the original code, unchanged. Throttle
logic lives in a separate private method (processThrottledNotifications).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mxmzb
mxmzb force-pushed the feat/notification-throttle-ms branch from a61367f to 4f2ee00 Compare April 2, 2026 15:08
@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Python Preview Packages

Version 0.0.0.dev1775146046 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.dev1775146046' --index testpypi

# Integrations (each already depends on the matching ag-ui-protocol preview)
uv add 'ag-ui-langgraph==0.0.0.dev1775146046' --index testpypi
uv add 'ag-ui-crewai==0.0.0.dev1775146046' --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.dev1775146046' --index testpypi
uv add 'ag_ui_adk==0.0.0.dev1775146046' --index testpypi
uv add 'ag_ui_strands==0.0.0.dev1775146046' --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.dev1775146046

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


Commit: 1c53b2b

mxmzb and others added 3 commits April 2, 2026 17:24
- Replace flat notificationThrottleMs/notificationMinChunkSize with
  grouped NotificationThrottleConfig { intervalMs, minChunkSize? }
- Add input validation (non-negative, finite) with clear error messages
- Make notificationThrottle readonly to prevent mid-run mutation
- Fix type safety: replace `as any` content access with proper
  role === "assistant" narrowing (prevents NaN from non-string content)
- Fix charsSinceLastNotify tracking across message boundaries by
  tracking message ID and resetting lastContentLength on identity change
- Add try-catch around subscriber calls in notify() to prevent a single
  throwing subscriber from crashing the pipeline
- Add disposed flag to prevent timer-fired notifications after stream
  teardown
- Fix JSDoc to accurately describe leading-edge + trailing behavior
- Expand test coverage from 3 to 11 tests: state changes, subscriber
  errors, clone preservation, input validation, large throttle windows

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Wrap subscriber calls in addMessage, addMessages, setMessages, setState,
and the throttle finalize flush with try-catch to prevent a single
throwing subscriber from blocking others or causing unhandled rejections.

Adds test for subscriber error isolation in addMessage path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mxmzb

mxmzb commented Apr 2, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by new PR from clean branch (feat/notification-throttle-ms-v2) — original branch had contamination from #1385.

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.

1 participant