Repository navigation
Push LLMOperator's token usage and cost to XCom - #74355
Merged
Merged
Conversation
kaxil
reviewed
Oct 7, 2026
pierrejeambrun
force-pushed
the
common-ai-llm-usage-xcom
branch
from
October 7, 2026 10:31
aa32c20 to
fd771c9
Compare
1 task done
pierrejeambrun
marked this pull request as ready for review
October 7, 2026 11:35
pierrejeambrun
requested review from
Lee-W,
amoghrajesh,
ashb,
bugraoz93,
gopidesupavan,
jason810496,
jscheffl and
potiuk
as code owners
October 7, 2026 11:35
pierrejeambrun
force-pushed
the
common-ai-llm-usage-xcom
branch
from
October 7, 2026 13:09
4867315 to
b001a6b
Compare
1 task done
kaxil
reviewed
Oct 7, 2026
Member
Author
|
Could do the same for |
pierrejeambrun
marked this pull request as draft
October 8, 2026 12:34
pierrejeambrun
force-pushed
the
common-ai-llm-usage-xcom
branch
from
October 14, 2026 14:47
b001a6b to
55fe90e
Compare
pierrejeambrun
marked this pull request as ready for review
October 14, 2026 15:26
Member
|
@pierrejeambrun Conflicts :( |
AgentOperator already exposes request/token/cost counts and a run id on XCom and stamps the task-instance identity on its GenAI spans; LLMOperator computed the same usage for its log summary but never published it, so there was no way to see what an LLMOperator run cost, or join it to its trace, without reading task logs. A run stopped by a cost limit is the one where this matters most, so the usage is pushed on a failed run too.
With do_xcom_push=False, the usage XCom was the only record of what a failed run spent, so a run stopped by a cost limit left no trace of its spend anywhere. Logging it matches what AgentOperator already does.
…b docs The feature map still said only @task.agent tasks show token counts and cost in the AI Model tab, which no longer holds now that LLMOperator pushes the same usage XCom.
Everything that runs after a run raises is reporting only and must never replace the run's own exception, the same rule AgentOperator follows for its failed-run report.
pierrejeambrun
force-pushed
the
common-ai-llm-usage-xcom
branch
from
October 19, 2026 08:49
bfeb976 to
fe77aad
Compare
1 task done
28 of 93 tasks
This was referenced Oct 29, 2026
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.
AgentOperatoralready exposes its request/token/cost counts and arun_idon XCom, and stamps the task-instance identity on its GenAI spans.LLMOperatorcomputed the same usage for its own log summary but never published it, so there was no way to see what anLLMOperatorrun cost, or to join it to its trace, without reading task logs. The AI Model tab reads theusageXCom, so for@task.llmtasks it could only show a bare model name.This brings
LLMOperator(and@task.llm) in line withAgentOperator, the same keys in the same shape, so tooling built on them works for both operators.A run stopped by a
cost_limitis the one where its spend matters most, so the partial usage is logged and pushed on a failed run too. Under the cross-attempt usage budget (Airflow >= 3.3 withusage_limitsset), theusageXCom is this attempt's own usage, not the running total, matchingAgentOperator.The other
LLM*operators (LLMBranchOperator,LLMSQLQueryOperator,LLMSchemaCompareOperator,LLMFileAnalysisOperator) overrideexecute()instead of callingLLMOperator's, so they are unchanged here. That is follow-up work.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.7, Opus 5.5) following the guidelines