.agents/references/tool-execution-lifecycle.md
Use this reference for changes to function-tool planning, approvals, tool guardrails, concurrency, cancellation, timeouts, hooks, error conversion, or resumed execution. Read Tool identity and routing when names, namespaces, lookup keys, or call IDs also change.
process_model_response() discovers executable work, but tool_planning.py decides which work may run now. Keep discovery, approval partitioning, and invocation as separate phases.
needs_approval checker again for a call whose status is already approved or rejected.RunState resume.FunctionTool invocation. Handoffs, hosted tools, built-in provider tools, and nested Agent.as_tool() runs have separate execution boundaries unless they explicitly opt into equivalent checks.SDK-side function-tool concurrency is independent of provider-side parallel tool-call generation. The provider controls how many calls appear in one response; RunConfig.tool_execution.max_function_tool_concurrency controls how many local function handlers run at once.
task.cancel() is not terminal cleanup. On sibling failure, drain cancelled handlers and wait for post-invocation work within the bounded cleanup policy. On parent cancellation, cancel remaining tasks and attach result callbacks so late exceptions are observed without delaying cancellation indefinitely.asyncio.to_thread() so they do not block the event loop. Async function tools run in the event loop and are the only decorated handlers that support SDK timeouts.timeout_behavior and timeout_error_function own timeout conversion; failure_error_function=None means ordinary exceptions propagate instead of becoming model-visible output.Computer implementations must be initialized and disposed by the run that acquired them.Agent.as_tool() execution owns a nested run loop and nested resumable state. Scope cached nested state by the parent RunState and call identity, not only by the reusable agent or tool object.AgentToolUseTracker records tool use per agent identity. When reset_tool_choice=True, reset the effective next-turn tool choice after that agent uses a tool so required or a named choice cannot force an accidental loop; do not mutate the agent's declared settings across independent runs.docs/running_agents.mddocs/tools.mddocs/guardrails.mddocs/human_in_the_loop.mdsrc/agents/run_internal/tool_planning.pysrc/agents/run_internal/tool_execution.pysrc/agents/tool.pytests/test_agent_runner.pytests/test_agent_runner_streamed.pytests/test_function_tool.pytests/test_tool_guardrails.pytests/test_tool_choice_reset.pytests/test_tool_use_tracker.pytests/test_run_state.py