Skip to content

Conversation

@cjohnhanson
Copy link

Enables CallDeferred and ApprovalRequired exceptions to carry arbitrary metadata via an optional metadata parameter. The metadata is accessible in DeferredToolRequests.metadata keyed by tool_call_id.

Backward compatible - metadata defaults to empty dict if not provided.

I still need to do a proper review of this, check against existing testing conventions, and at the very least I'll be rewriting part of the docs updates, but opening as Draft for visibility and early feedback.

Enables CallDeferred and ApprovalRequired exceptions to carry arbitrary
metadata via an optional `metadata` parameter. The metadata is accessible
in DeferredToolRequests.metadata keyed by tool_call_id.

This allows tools to:
- Provide cost/time estimates for approval decisions
- Include task IDs for external execution tracking
- Store context about why approval is required
- Attach priority or urgency information

Backward compatible - metadata defaults to empty dict if not provided.
Extract metadata population logic into separate _populate_deferred_calls
helper function to reduce cyclomatic complexity from 16 to 15.

pass
def __init__(self, metadata: dict[str, Any] | None = None):
self.metadata = metadata or {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

If there's no metadata, I'd rather store None, and not add the tool_call_id to DeferredToolRequests.metadata at all

Args:
metadata: Optional dictionary of metadata to attach to the deferred tool call.
This metadata will be available in `DeferredToolRequests.metadata` keyed by `tool_call_id`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

You'll want to update the TemporalWrapperToolset._{un}wrap_call_tool_result methods to consider the new metadata arg as well

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.

2 participants