Run tool calls as DBOS child workflows via `child_workflow` tool metadata in `DBOSDurability`
No issue: this is item 1 of the harness durable-parity audit (DBOS child-workflow tool calls, for parity with Temporal's #7329).
Why
Temporal can run a tool call as a child workflow (#7329), but DBOS had no opt-in for this. A nested DBOSDurability agent run from a tool recorded its steps in the parent's history.
New public surface
pydantic_ai.durable_exec.dbos.ChildWorkflowConfig(one option,workflow_timeout_sec, which is passed to DBOS'sSetWorkflowTimeout)- Tool metadata
{'dbos': {'child_workflow': ChildWorkflowConfig(...)}}, set on the tool or throughSetToolMetadata
User-visible behavior
delegation = FunctionToolset(id='delegation')
@delegation.tool_plain(
+ metadata={'dbos': {'child_workflow': ChildWorkflowConfig(workflow_timeout_sec=600)}}
)
async def research(topic: str) -> str:
return (await researcher.run(f'Research: {topic}')).output
-# researcher's steps are recorded in the parent `lead` workflow's history
+# each call runs as workflow `lead__function_toolset__delegation.call_tool__child_workflow`, holding researcher's steps
An async function tool marked this way runs as the DBOS workflow {agent}__function_toolset__{toolset_id}.call_tool__child_workflow. Its inputs are the tool name, args, the tool definition the parent already prepared, the serialized run context and deps. Inside the workflow the tool is rebuilt with FunctionToolset.tool_for_tool_def (so prepare doesn't run again), and the run context and deadline are restored, so the nested agent's steps go into the child's history. On recovery the child resumes from its own checkpoints. Invalid metadata, sync tools, and marked tools in a toolset with no registered child workflow raise UserError.
Verification
test_dbos_child_workflow_tool_survives_recovery: crashes inside the child, then resumes. The researcher model is called once, the unmarked tool re-runs in parent workflow code, and workflow/step names, the timeout and the deadline are pinned. Failed on main (no child workflow was created:Right contains one more item: ('-3', 'child_wf_lead__function_toolset__<agent>.call_tool__child_workflow', 'PENDING')).test_dbos_child_workflow_via_set_tool_metadata,test_dbos_child_workflow_metadata_errors,test_dbos_child_workflow_requires_a_registered_toolset,test_dbos_toolsets_without_child_workflow_tools_stay_unwrapped, plus a compat pin (DBOS_CHILD_WORKFLOW_NAMES) and the regeneratedscripts/durable_exec_contract.json.test_dbos.pyandtest_durable_exec_compat.pypass locally, excepttest_dbos_mcp_toolset_get_instructions_uses_local_when_initializedandtest_multiple_agents. Both fail the same way on main locally (subprocess cost guard on the MCP server).
What changes for existing users
Nothing: child workflows are registered, and toolsets wrapped, only for toolsets that select child_workflow when the agent is constructed.
PR decisions
tool_config_keystaysNone. Setting it would turn on{'dbos': False}opt-outs and per-tool step-config merging for existing users. The only metadata read ischild_workflow.- A child workflow is registered only for opted-in toolsets, when the agent is bound: the toolset holds a tool whose metadata selects
child_workflow, or a construction-timeSetToolMetadataselects it. DBOS needs the workflow registered beforeDBOS.launch()to recover it, and hashes registered workflows into the application version, so unmarked agents register nothing. A tool selected after construction (@agent.tool(metadata=...)afterAgent(...)) raises aUserErrorin a workflow, explaining how to select it at construction. I didn't add aDBOSDurabilityflag for that case (YAGNI). This replaces the first version, which registered a workflow for every toolset with anid; douwebot flagged that it changed every user's app version. - Toolsets are only wrapped at run time when needed. That is, when a toolset holds a marked tool or a
SetToolMetadatamarkschild_workflow, so unmarked runs keep the original toolset tree. - Shared selection helpers:
selects_child_workflow,capability_selects_child_workflowandtoolset_selects_child_workflowindurable_exec/_base.pyare now used by both Temporal and DBOS, so their detection rules can't drift apart. Temporal's behavior is unchanged. ChildWorkflowConfigis validated with aTypeAdapter(extra='forbid'), the same way as Temporal'sChildWorkflowConfig.- The child workflow body delegates to a method, because DBOS hashes registered workflow source into the application version.
ChildWorkflowConfighas one option, a per-invocation timeout, because DBOS has no other per-child options. Registration-level options (max_recovery_attempts) are shared per toolset.- Known limitation: a
SetToolMetadatapassed at run time, or apreparefunction that addschild_workflow, is only honored in toolsets that already register a child workflow. In any other toolset the tool runs inline. Selecting at dispatch would mean registering and wrapping every function toolset. - Bot findings: a
preparethat reads the full run context failed in the child, now fixed viatool_for_tool_def. Declined, with replies on each thread: re-checkingdepsserialization (it's DBOS's behavior for every workflow input) and a parent check on the child workflow (it would block DBOS recovery or cost a database read on every call; starting workflows by name already requires system-DB access). - Out of scope: parallel marked tools starting child workflows concurrently rely on DBOS's step-ordering rules. That is item 2 (parallel tool calls).
- Pre-push review: 3 local reviews were run (the 1st couldn't read its inputs). All findings were fixed: contract manifest, loud error for unregistered toolsets including via
SetToolMetadata, recovered-child deadline, docs, unmarked-path test.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.