fix: AgentRunResult.usage API compatibility on pydantic-ai 2.x - #1091
fix: AgentRunResult.usage API compatibility on pydantic-ai 2.x#1091vitali87 wants to merge 3 commits into
Conversation
The latest AgentRunResult exposes 'usage' as a property instead of a callable method. Replace: response.usage() with: response.usage This fixes: TypeError: 'RunUsage' object is not callable when running 'cgr start' with newer versions of pydantic-ai/OpenAI agent libraries.
…mock usage as a property
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (6)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughThe PR updates ChangesProvider and usage compatibility
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryUpdates pydantic-ai compatibility for current releases: agent usage accounting reads the result usage property, and Vertex model creation uses Confidence Score: 5/5
What T-Rex did
Reviews (1): Last reviewed commit: "test: pin the Vertex branch of GooglePro..." | Re-trigger Greptile |
|



Based on #964 by @subhamruhela13.
Summary
A fresh
pip install code-graph-ragresolves pydantic-ai 2.x, whereAgentRunResult.usageis a property; the interactive chat then crashes on its first response withTypeError: 'RunUsage' object is not callableatcodebase_rag/main.py:655. The dev lock held pydantic-ai 1.102.0 (whereusageis still a method), which is why the suite stayed green while every fresh install was broken.Changes
response.usage()->response.usage(cherry-picked from fix: AgentRunResult.usage API compatibility #964, authorship preserved)pydantic-ai>=2.0.0floor (the property landed in 2.0.0; verifiedGoogleCloudProvider,AgentRetries, and the deferred-tools API all exist there) anduv.lockupgraded to 2.24.0GoogleProvider(project=..., location=..., credentials=...)(removed in 2.x) toGoogleCloudProvider, the same construction path 1.102.0 delegated to behind a deprecation warninggriffe>=1.0,<2workaround: pydantic-ai 2.x declaresgriffelib, which installs the same top-levelgriffe/package, so the old pin made both packages write one directoryReview fixes applied
usage.return_valuemocks intest_model_switching.pynow assignRunUsageproperty-style, so the loop consumes realistic token dataGoogleCloudProvider(project/location/credentials); without it the suite passes even if the Vertex path is reverted to the 1.x constructorTest plan
uv run pytest -m "not integration and not e2e and not slow": 6459 passed;test_vector_store.py+test_unixcoder_unit.pypass with thesemantic/milvusextras installedcgr startchat against local Ollama completes with realRunUsagetoken accounting instead of the TypeErrorty checkclean with the repo's pre-commit scopingSummary by CodeRabbit
New Features
Bug Fixes
Documentation