Skip to content

Conversation

@mattbrandman
Copy link
Contributor

@mattbrandman mattbrandman commented Nov 15, 2025

This adds the usage field to the context that is by default passed to temporal activities. This is useful if each individual message of an agents execution needs / wants to know the usage up to that point. This can be extremely useful if you are doing some type of cancellation flow and need the information to provide to a cancellation handler to save usage up to that point. Usage would not include the current message which would need to be approximated by the end user if it was of vital importance.

Closes #3420

@mattbrandman
Copy link
Contributor Author

@DouweM for review whenever you get a chance no rush on this

'max_retries': ctx.max_retries,
'run_step': ctx.run_step,
'partial_output': ctx.partial_output,
'usage': ctx.usage,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, let's update the docstring on line 17, as well as the Temporal doc in the "run context" section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good

@DouweM DouweM self-assigned this Nov 17, 2025
@mattbrandman mattbrandman force-pushed the temporal-usage-on-context branch from e338b7e to 2ac363e Compare November 18, 2025 15:49
@mattbrandman mattbrandman force-pushed the temporal-usage-on-context branch from befa4d1 to 8a1e022 Compare November 18, 2025 15:52
@mattbrandman
Copy link
Contributor Author

@DouweM rebased and updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Access RunContext.usage from Temporal event stream handler

2 participants