fix(agent): preserve complete model usage pricing#39201
Merged
Conversation
zyssyz123
requested review from
QuantumGhost,
crazywoola and
laipz8200
as code owners
July 17, 2026 10:30
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-07-20 07:49:06.884176334 +0000
+++ /tmp/pyrefly_pr.txt 2026-07-20 07:49:02.088167554 +0000
@@ -1763,17 +1763,17 @@
ERROR Argument `dict[str, object]` is not assignable to parameter `configs` with type `Mapping[str, LayerConfigInput] | None` in function `agenton.compositor.core.Compositor._create_run` [bad-argument-type]
--> tests/unit_tests/clients/agent_backend/test_cleanup_composition_compositor_integration.py:97:17
ERROR Cannot index into `bool` [bad-index]
- --> tests/unit_tests/clients/agent_backend/test_event_adapter.py:55:12
+ --> tests/unit_tests/clients/agent_backend/test_event_adapter.py:57:12
ERROR Cannot index into `float` [bad-index]
- --> tests/unit_tests/clients/agent_backend/test_event_adapter.py:55:12
+ --> tests/unit_tests/clients/agent_backend/test_event_adapter.py:57:12
ERROR Cannot index into `int` [bad-index]
- --> tests/unit_tests/clients/agent_backend/test_event_adapter.py:55:12
+ --> tests/unit_tests/clients/agent_backend/test_event_adapter.py:57:12
ERROR Cannot index into `list[JsonValue]` [bad-index]
- --> tests/unit_tests/clients/agent_backend/test_event_adapter.py:55:12
+ --> tests/unit_tests/clients/agent_backend/test_event_adapter.py:57:12
ERROR Cannot index into `str` [bad-index]
- --> tests/unit_tests/clients/agent_backend/test_event_adapter.py:55:12
+ --> tests/unit_tests/clients/agent_backend/test_event_adapter.py:57:12
ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/clients/agent_backend/test_event_adapter.py:55:12
+ --> tests/unit_tests/clients/agent_backend/test_event_adapter.py:57:12
ERROR Object of class `list` has no attribute `startswith` [missing-attribute]
--> tests/unit_tests/clients/agent_backend/test_request_builder.py:159:12
ERROR Class member `_FailedStatusClient.wait_run` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
@@ -3180,29 +3180,37 @@
ERROR Object of class `FunctionType` has no attribute `return_value` [missing-attribute]
--> tests/unit_tests/core/app/apps/agent_app/test_app_generator.py:465:25
ERROR Object of class `NoneType` has no attribute `message` [missing-attribute]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:563:12
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:576:12
ERROR Object of class `NoneType` has no attribute `model` [missing-attribute]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:564:12
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:577:12
ERROR Object of class `NoneType` has no attribute `message` [missing-attribute]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:646:12
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:659:12
ERROR Object of class `NoneType` has no attribute `message` [missing-attribute]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:666:12
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:679:12
ERROR Object of class `NoneType` has no attribute `message` [missing-attribute]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:713:12
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:726:12
ERROR Object of class `NoneType` has no attribute `usage` [missing-attribute]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:714:12
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:727:12
ERROR Object of class `NoneType` has no attribute `usage` [missing-attribute]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:715:12
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:728:12
ERROR Object of class `NoneType` has no attribute `usage` [missing-attribute]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:716:12
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:729:12
+ERROR Object of class `NoneType` has no attribute `usage` [missing-attribute]
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:730:12
+ERROR Object of class `NoneType` has no attribute `usage` [missing-attribute]
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:731:12
+ERROR Object of class `NoneType` has no attribute `usage` [missing-attribute]
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:732:12
+ERROR Object of class `NoneType` has no attribute `usage` [missing-attribute]
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:733:12
ERROR Object of class `NoneType` has no attribute `message` [missing-attribute]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:737:12
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:754:12
ERROR Object of class `NoneType` has no attribute `message` [missing-attribute]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:755:12
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:772:12
ERROR Object of class `NoneType` has no attribute `message` [missing-attribute]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:773:12
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:790:12
ERROR Object of class `NoneType` has no attribute `message` [missing-attribute]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:794:12
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:811:12
ERROR Object of class `NoneType` has no attribute `message` [missing-attribute]
--> tests/unit_tests/core/app/apps/agent_app/test_input_guards.py:67:12
ERROR Object of class `NoneType` has no attribute `prompt_messages` [missing-attribute]
@@ -6304,7 +6312,7 @@
ERROR Cannot index into `dict[str, JsonValue]` [bad-index]
--> tests/unit_tests/core/workflow/nodes/agent_v2/test_dify_tools_builder.py:393:43
ERROR Argument `object` is not assignable to parameter `output` with type `Decimal | Iterable[Any] | Mapping[str, Any] | bool | bytearray | bytes | float | int | str | None` in function `clients.agent_backend.event_adapter.AgentBackendRunSucceededInternalEvent.__init__` [bad-argument-type]
- --> tests/unit_tests/core/workflow/nodes/agent_v2/test_output_adapter.py:49:16
+ --> tests/unit_tests/core/workflow/nodes/agent_v2/test_output_adapter.py:50:16
ERROR Object of class `FromClause` has no attribute `create` [missing-attribute]
--> tests/unit_tests/core/workflow/nodes/agent_v2/test_output_file_rebacker.py:22:5
ERROR Cannot index into `object` [bad-index]
|
Contributor
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #39201 +/- ##
==========================================
- Coverage 85.73% 85.68% -0.06%
==========================================
Files 5122 4960 -162
Lines 281146 276518 -4628
Branches 55277 54055 -1222
==========================================
- Hits 241036 236923 -4113
+ Misses 35497 34983 -514
+ Partials 4613 4612 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
zyssyz123
enabled auto-merge
July 20, 2026 02:14
linw1995
approved these changes
Jul 20, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to no response for status checks
Jul 20, 2026
lyzno1
enabled auto-merge
July 20, 2026 07:49
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.
Summary
LLMUsagereturned by plugin daemon model calls instead of reducing it to token countsRoot cause
The Agent model adapter converted plugin daemon
LLMUsageinto Pydantic AIRequestUsage, which only carries token counts. The terminal Agent event therefore omitted pricing fields. API reconstructedLLMUsagefrom that incomplete payload and persistedtotal_price = 0, so Agent Monitor correctly aggregated a zero database value.Verification
79 passed68 passed0 errorsdeploy/agentverified both Agent backend and API/worker images use the fix commit5,368tokens /$0.027165knowledge_base_search): aggregated11,401tokens /$0.05853, matching persisted message usage6,412tokens /$0.040760, matching node execution metadataLinear: https://linear.app/dify/issue/DIFY-2815/agent-monitor-%E7%9A%84-token-usage-%E6%98%BE%E7%A4%BA%E9%97%AE%E9%A2%98