fix(pydantic-ai): preserve usage in structured results - #31
Closed
mikemikimike wants to merge 1 commit into
Closed
mikemikimike wants to merge 1 commit into
mikemikimike wants to merge 1 commit into
Conversation
4 tasks
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.
Related issue
Closes #28
Background
The PydanticAI adapter read real token counts but appended them to
evaluation_contextas text. This left the structured audit usage empty and polluted evaluator-visible text with accounting metadata.Changes
Result.usage.evaluation_context.Implementation and compatibility
The adapter now uses the existing ECP
Result.usagecontract, which the runtime audit layer aggregates across steps. No protocol shape or public adapter constructor changes; only the previously empty usage field and evaluation-context content change for PydanticAI results that report usage.Tests
python scripts/seed_adapter_fixtures.py— regenerated fixture; usage is{"input_tokens": 61, "output_tokens": 14}.PYTHONPATH=sdk/python/src;runtime/python/src python -m unittest sdk/python/tests/test_adapters.py sdk/python/tests/test_adapter_conformance.py— 11 passed.PYTHONPATH=sdk/python/src;runtime/python/src python -m unittest discover sdk/python/tests -p 'test_*.py'— 37 passed.PYTHONPATH=sdk/python/src;runtime/python/src python -m unittest runtime/python/tests/test_audit.py— 14 passed.ruff check sdk/python/src/ecp/adaptors/pydantic_ai.py sdk/python/tests/test_adapters.py scripts/seed_adapter_fixtures.py— passed.Checks not run or environment limitations
ruff format --checkreports pre-existing formatting differences in the touched adapter/test files and the seed script; no unrelated formatting was included.