Skip to content

[Python SDK] Tool execution timeout does not break execute_tool_call_loop early #354

@santoshkumarradha

Description

@santoshkumarradha

Summary

When a tool call inside agentfield.tool_calling.execute_tool_call_loop raises asyncio.TimeoutError, the loop does not terminate or short-circuit. Instead it continues to spend additional turns calling the LLM, which is wasteful (cost + latency) and confusing for debugging.

Where

  • File: sdk/python/agentfield/tool_calling.py
  • Function: execute_tool_call_loop
  • Discovered by: sdk/python/tests/test_tool_calling_error_paths.py::test_tool_execution_timeout_breaks_loop_early (currently skipped with pytest.skip("source bug: tool timeouts do not break the loop early"))

Reproduction

agent.call = AsyncMock(side_effect=asyncio.TimeoutError("tool timed out"))
# ... feed LLM response with one tool call ...
_, trace = await execute_tool_call_loop(
    agent=agent,
    messages=messages,
    tools=[make_tool_schema()],
    config=ToolCallConfig(max_turns=3),
    ...
)
# Expected: make_completion.await_count == 1 (loop bailed after the timeout)
# Actual:   loop continues, await_count > 1

Expected behavior

When a tool execution raises asyncio.TimeoutError:

  1. Record the timeout in the ToolCallTrace for that call
  2. Append an error message to messages describing the timeout
  3. Break out of the loop (do not call the LLM again) — timeouts indicate a real environmental failure that retrying with the same tool will not fix in the same execution

If we want a configurable behavior (continue vs. break), it should default to break and be opt-out via ToolCallConfig.

Acceptance criteria

  • Tool call asyncio.TimeoutError terminates the loop after the current turn
  • Trace records the timeout reason on the offending call
  • make_completion.await_count == 1 in the reproduction above
  • The skipped test in test_tool_calling_error_paths.py::test_tool_execution_timeout_breaks_loop_early is unskipped and passes

Discovered via

PR #352 (test coverage improvements). One of 5 source bugs surfaced while writing failure-mode tests for the Python SDK.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-friendlyWell-documented task suitable for AI-assisted developmentarea:aiAI/LLM integrationbugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is neededsdk:pythonPython SDK relatedtestsUnit test improvements and coverage

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions