Skip to content

Conversation

@cjohnhanson
Copy link

@cjohnhanson cjohnhanson commented Nov 5, 2025

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.

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.
Per Douwe's comments:
1. Store None instead of {} when no metadata provided
2. Don't add tool_call_id to metadata dict when None
3. Update Temporal wrap/unwrap methods to handle metadata

- Updated test assertions to reflect None metadata behavior
- Updated doc example snapshots to show metadata={}
- Fixed codespell issue with table formatting
@cjohnhanson cjohnhanson force-pushed the feat/deferred-tool-metadata branch from 7e17594 to 42cf5b8 Compare November 7, 2025 21:53
- Replace contrived task_id parameter with realistic tool signatures
- Add ComputeDeps class demonstrating dependency injection pattern
- Show using ctx.deps to compute metadata from tool arguments
- Remove incorrect statement about backwards compatibility
- Update test_examples.py to match new realistic example
- Add mock model responses for flight booking example
- Update documentation snapshots to include metadata field
- Follow existing pattern for deferred tool testing
- Complete test_approval_required_without_metadata() by running agent
  with approval results to hit the tool implementation line
- Complete test_mixed_deferred_tools_with_metadata() by running agent
  with all deferred tool results to hit tool implementation lines
- Remove unreachable branch check in _populate_deferred_calls() - keys
  are always present in both dicts by construction

This achieves 100% coverage for the deferred tool metadata feature.
@cjohnhanson cjohnhanson marked this pull request as ready for review November 7, 2025 23:53
@cjohnhanson cjohnhanson requested a review from DouweM November 7, 2025 23:53
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