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
Draft
Conversation
…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>
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.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 testpypiInstall with pippip install \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple/ \
ag-ui-protocol==0.0.0.dev1784050417
Commit: 1fb3d02 |
@ag-ui/a2a-middleware
@ag-ui/a2ui-middleware
@ag-ui/event-throttle-middleware
@ag-ui/mcp-apps-middleware
@ag-ui/mcp-middleware
@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/llamaindex
@ag-ui/mastra
@ag-ui/pydantic-ai
@ag-ui/vercel-ai-sdk
@ag-ui/watsonx
@ag-ui/a2ui-toolkit
create-ag-ui-app
@ag-ui/client
@ag-ui/core
@ag-ui/encoder
@ag-ui/proto
commit: |
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.
Warning
Draft — blocked on a release. CI will be red until the steps below are done.
These integrations install the published
ag-ui-protocolfrom PyPI, soTokenUsage(added by #2188) is not importable here yet.Summary
Follow-up to #2188. Adds the Python integration producers that populate the AG-UI
usagefield onRUN_FINISHED, completing OSS-351 for Python.usage_metadatafrom chat-model stream chunks (dependency-freeusage.py+ agent wiring).AgentResult.metrics.accumulated_usagefrom the terminalresultevent; labels provider from the model class + model config.Numeric counts and
provider/modellabels only — never prompts, completions, messages, or identifiers.⛔ Release ordering — do NOT merge until
ag_ui.core.TokenUsage).ag-ui-protocolto PyPI withTokenUsage(cut fromsdks/python).ag-ui-protocolpin inintegrations/langgraph/python/pyproject.tomlandintegrations/aws-strands/python/pyproject.tomlto that release, and refresh eachuv.lock.Only after step 3 will
uv syncinstall a protocol package that exposesTokenUsage, so thelanggraph-python/aws-strands-pythonCI 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/pythonbuild (viaPYTHONPATH): unit tests for the usage mappers, wiring tests driving the realrun()to aRUN_FINISHEDcarrying 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