Derive capability-contributed toolset `id` from the capability for durable execution
- Closes #6334
Problem
Toolsets contributed by capabilities via get_toolset() were built with id=None:
Capability(tools=[...])→FunctionToolset(tools)MCP(url=...)/MCP(local=...)→ localMCPToolsetNativeOrLocalTool(local=<callable>)→FunctionToolset([tool])(base forWebSearch/WebFetch/ImageGeneration)
Durable-exec engines wrap leaf toolsets by id at construction time, so combining a capability with durable execution broke:
- Temporal raised
UserErroratTemporalAgent(...)construction (the reported, reproduced symptom). - DBOS / Prefect couldn't give the leaf a stable, unique step/task name.
The error was correct but unactionable — neither Capability nor MCP exposed a way to set the contributed toolset's id.
Fix
Stamp the contributed leaf toolset's id from the capability, at construction time (per-capability):
Capability→FunctionToolset(tools, id=id)NativeOrLocalTool(local callable) →FunctionToolset([...], id=self.id)MCP→ the localMCPToolsetgets_derive_id(url)(explicitid→ nativeMCPServerToolid → host+slug from the URL). This is fed to both the URL-built local toolset and theMCPToolsetauto-wrapped from a non-URLlocal=input.
So the actionable contract is Capability(id='billing', tools=[...]) / MCP(id='docs', url='...'). User-provided toolsets (toolsets=[...], local=<MCPToolset>) keep their own ids and are never overwritten.
MCP._resolved_id was refactored to delegate to _derive_id. For the local='https://…' override (where self.url may be None) the id is derived from the concrete URL being connected to. When there's genuinely nothing to derive from — a native=<callable> factory paired with a local fallback, with no url= and no id= — it now raises an actionable UserError instead of the bare AssertionError it did before.
Design decisions for a sanity pass @DouweM
- Per-capability derivation vs centralized. I stamp the id at each capability rather than centralizing in
CapabilityOwnedToolset. Centralizing would mutate ids on user-provided toolset instances (label/uniqueness side effects); per-capability is the safer first step. Happy to centralize if you'd prefer. - id-less capability with nothing to derive from. A
Capability(tools=...)/MCP(local=<client>)with no explicitid, no native tool, and no URL keepsid=None(status quo, non-breaking). The alternative is to raise a clearer error at construction telling the user to setid=. I left it asNone; flagging the choice since it's the crux of "making the error actionable." MCP(local=<non-URL client>)(Path / transport /FastMCP/Client) hit the sameid=Nonedefect (reproduced:MCP(id='x', local=Path(...))→id=None). I included it for sibling-consistency (one-line reorder + kwarg) rather than leaving a gap. Shout if you'd rather scope it out.
Notes
- Issue #5885 (DBOS silently collided on id-less MCP leaf toolsets) was fixed by #6406, which makes DBOS reject id-less MCP leaf toolsets at construction — the same stricter contract Temporal already enforces. This PR makes that contract actionable for capability users: a capability-contributed
MCPleaf now derives anid, so it passes both the Temporal and DBOS guards (covered by regression tests on each).
Tests
tests/test_capabilities.py— id stamping forCapability,NativeOrLocalTool, and everyMCPderivation branch (URL slug, explicit id, native id, override-URL, non-URL client, nothing-to-derive →None), plus anative=<callable>with nothing to derive → actionableUserError.tests/test_temporal.py— regression:TemporalAgent(Agent(capabilities=[Capability(id='billing', ...), MCP(id='docs', ...)]))no longer raises and registers activities named after the capability ids, plus a deferred-capability (defer_loading=True) variant.tests/test_dbos.py— regression: a capability-contributedMCP(url=...)leaf with no explicitidderives its id from the URL and passes the DBOS id-less-MCP guard.
Checklist
- Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
- No breaking changes in accordance with the version policy.
- PR title is fit for the release changelog.