_generate_tool_call_response() — anthropic-sdk-python Function Reference
Architecture documentation for the _generate_tool_call_response() function in _beta_runner.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD b5b59a19_0646_9f18_1716_6cbb729f18af["_generate_tool_call_response()"] e1032e12_8173_7783_f9c6_c9b9260e5366["BaseAsyncToolRunner"] b5b59a19_0646_9f18_1716_6cbb729f18af -->|defined in| e1032e12_8173_7783_f9c6_c9b9260e5366 d1f2e83f_ca29_2f3a_83b4_5a5af4a46b73["_generate_tool_call_response()"] d1f2e83f_ca29_2f3a_83b4_5a5af4a46b73 -->|calls| b5b59a19_0646_9f18_1716_6cbb729f18af e6eb0ae3_dad5_13a8_e981_1b176438b0fe["generate_tool_call_response()"] e6eb0ae3_dad5_13a8_e981_1b176438b0fe -->|calls| b5b59a19_0646_9f18_1716_6cbb729f18af f070b824_7b1c_09b2_23ba_84bb23647a08["_get_last_assistant_message_content()"] b5b59a19_0646_9f18_1716_6cbb729f18af -->|calls| f070b824_7b1c_09b2_23ba_84bb23647a08 d1f2e83f_ca29_2f3a_83b4_5a5af4a46b73["_generate_tool_call_response()"] b5b59a19_0646_9f18_1716_6cbb729f18af -->|calls| d1f2e83f_ca29_2f3a_83b4_5a5af4a46b73 4970c546_0fad_9c03_1498_9ae6f7952dcf["append_messages()"] b5b59a19_0646_9f18_1716_6cbb729f18af -->|calls| 4970c546_0fad_9c03_1498_9ae6f7952dcf 1bc72768_ba8a_bbf8_09cb_913ba8fc3d53["beta_async_tool()"] b5b59a19_0646_9f18_1716_6cbb729f18af -->|calls| 1bc72768_ba8a_bbf8_09cb_913ba8fc3d53 a8a826cb_6a24_e00c_d9e5_15019ac4edb0["call()"] b5b59a19_0646_9f18_1716_6cbb729f18af -->|calls| a8a826cb_6a24_e00c_d9e5_15019ac4edb0 style b5b59a19_0646_9f18_1716_6cbb729f18af fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/anthropic/lib/tools/_beta_runner.py lines 552–598
async def _generate_tool_call_response(self) -> BetaMessageParam | None:
content = await self._get_last_assistant_message_content()
if not content:
return None
tool_use_blocks = [block for block in content if block.type == "tool_use"]
if not tool_use_blocks:
return None
results: list[BetaToolResultBlockParam] = []
for tool_use in tool_use_blocks:
tool = self._tools_by_name.get(tool_use.name)
if tool is None:
warnings.warn(
f"Tool '{tool_use.name}' not found in tool runner. "
f"Available tools: {list(self._tools_by_name.keys())}. "
f"If using a raw tool definition, handle the tool call manually and use `append_messages()` to add the result. "
f"Otherwise, pass the tool using `beta_async_tool(func)` or a `@beta_async_tool` decorated function.",
UserWarning,
stacklevel=3,
)
results.append(
{
"type": "tool_result",
"tool_use_id": tool_use.id,
"content": f"Error: Tool '{tool_use.name}' not found",
"is_error": True,
}
)
continue
try:
result = await tool.call(tool_use.input)
results.append({"type": "tool_result", "tool_use_id": tool_use.id, "content": result})
except Exception as exc:
log.exception(f"Error occurred while calling tool: {tool.name}", exc_info=exc)
results.append(
{
"type": "tool_result",
"tool_use_id": tool_use.id,
"content": repr(exc),
"is_error": True,
}
)
return {"role": "user", "content": results}
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does _generate_tool_call_response() do?
_generate_tool_call_response() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/lib/tools/_beta_runner.py.
Where is _generate_tool_call_response() defined?
_generate_tool_call_response() is defined in src/anthropic/lib/tools/_beta_runner.py at line 552.
What does _generate_tool_call_response() call?
_generate_tool_call_response() calls 5 function(s): _generate_tool_call_response, _get_last_assistant_message_content, append_messages, beta_async_tool, call.
What calls _generate_tool_call_response()?
_generate_tool_call_response() is called by 2 function(s): _generate_tool_call_response, generate_tool_call_response.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free