Skip to content

feat(python): token usage producers for LangGraph + AWS Strands (OSS-351) [blocked on ag-ui-protocol release]#2190

Draft
BenTaylorDev wants to merge 1 commit into
mainfrom
ben1/oss-351-python-usage-producers
Draft

feat(python): token usage producers for LangGraph + AWS Strands (OSS-351) [blocked on ag-ui-protocol release]#2190
BenTaylorDev wants to merge 1 commit into
mainfrom
ben1/oss-351-python-usage-producers

Conversation

@BenTaylorDev

Copy link
Copy Markdown
Contributor

Warning

Draft — blocked on a release. CI will be red until the steps below are done.
These integrations install the published ag-ui-protocol from PyPI, so TokenUsage (added by #2188) is not importable here yet.

Summary

Follow-up to #2188. Adds the Python integration producers that populate the AG-UI usage field on RUN_FINISHED, completing OSS-351 for Python.

  • LangGraph (python) — maps usage_metadata from chat-model stream chunks (dependency-free usage.py + agent wiring).
  • AWS Strands (python) — reads AgentResult.metrics.accumulated_usage from the terminal result event; labels provider from the model class + model config.

Numeric counts and provider/model labels only — never prompts, completions, messages, or identifiers.

⛔ Release ordering — do NOT merge until

  1. Merge feat(core): token usage on terminal run events + TS producers (OSS-350/351) #2188 (the protocol contract, incl. ag_ui.core.TokenUsage).
  2. Release ag-ui-protocol to PyPI with TokenUsage (cut from sdks/python).
  3. Bump the ag-ui-protocol pin in integrations/langgraph/python/pyproject.toml and integrations/aws-strands/python/pyproject.toml to that release, and refresh each uv.lock.

Only after step 3 will uv sync install a protocol package that exposes TokenUsage, so the langgraph-python / aws-strands-python CI jobs can pass. Until then this PR is expected red — that's why it's a draft.

Testing (already done locally)

Validated against a local sdks/python build (via PYTHONPATH): unit tests for the usage mappers, wiring tests driving the real run() to a RUN_FINISHED carrying usage, and full integration suites green. The LangGraph-python path was additionally verified end-to-end against a live OpenAI model (real provider/model + token counts).

Refs #604. Depends on #2188.

🤖 Generated with Claude Code

…S-351, Python)

Follow-up to #2188. Adds the Python integration producers that populate the
AG-UI `usage` field introduced by #2188's protocol contract.

- LangGraph (python): map usage_metadata from chat-model stream chunks
  (dependency-free usage.py + agent wiring).
- AWS Strands (python): read AgentResult.metrics.accumulated_usage from the
  terminal result event; label provider from the model class + model config.

Only numeric counts and provider/model labels are read — no prompts,
completions, messages, or identifiers.

BLOCKED ON RELEASE: these integrations install the published `ag-ui-protocol`
from PyPI, so `TokenUsage` is not importable until #2188 lands AND a new
`ag-ui-protocol` is released that includes it. Before this PR can go green /
leave draft:
  1. Merge #2188.
  2. Release `ag-ui-protocol` with `TokenUsage` (from sdks/python).
  3. Bump the `ag-ui-protocol` pin in each integration's pyproject.toml to that
     release and refresh uv.lock.

Refs #604.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Python Preview Packages

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

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

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


Commit: 1fb3d02

@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 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@2190

@ag-ui/a2ui-middleware

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

@ag-ui/event-throttle-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/event-throttle-middleware@2190

@ag-ui/mcp-apps-middleware

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

@ag-ui/mcp-middleware

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

@ag-ui/a2a

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

@ag-ui/adk

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

@ag-ui/ag2

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

@ag-ui/agno

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

@ag-ui/aws-strands

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

@ag-ui/claude-agent-sdk

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

@ag-ui/crewai

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

@ag-ui/langchain

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

@ag-ui/langgraph

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

@ag-ui/llamaindex

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

@ag-ui/mastra

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

@ag-ui/pydantic-ai

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

@ag-ui/vercel-ai-sdk

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

@ag-ui/watsonx

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/watsonx@2190

@ag-ui/a2ui-toolkit

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/a2ui-toolkit@2190

create-ag-ui-app

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

@ag-ui/client

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

@ag-ui/core

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

@ag-ui/encoder

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

@ag-ui/proto

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

commit: 4b4adb8

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