_create_tool_selection_response() — langchain Function Reference
Architecture documentation for the _create_tool_selection_response() function in tool_selection.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 80d478df_8f9e_226e_c90e_c056581780f1["_create_tool_selection_response()"] 740a7da1_ca4f_8c85_71e0_4f92696f1237["tool_selection.py"] 80d478df_8f9e_226e_c90e_c056581780f1 -->|defined in| 740a7da1_ca4f_8c85_71e0_4f92696f1237 79ce050f_9134_368b_2f3c_59dd0f33524c["wrap_model_call()"] 79ce050f_9134_368b_2f3c_59dd0f33524c -->|calls| 80d478df_8f9e_226e_c90e_c056581780f1 914b6a96_704c_ef23_6236_b6d24e64245f["awrap_model_call()"] 914b6a96_704c_ef23_6236_b6d24e64245f -->|calls| 80d478df_8f9e_226e_c90e_c056581780f1 style 80d478df_8f9e_226e_c90e_c056581780f1 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/langchain/agents/middleware/tool_selection.py lines 47–78
def _create_tool_selection_response(tools: list[BaseTool]) -> TypeAdapter[Any]:
"""Create a structured output schema for tool selection.
Args:
tools: Available tools to include in the schema.
Returns:
`TypeAdapter` for a schema where each tool name is a `Literal` with its
description.
Raises:
AssertionError: If `tools` is empty.
"""
if not tools:
msg = "Invalid usage: tools must be non-empty"
raise AssertionError(msg)
# Create a Union of Annotated Literal types for each tool name with description
# For instance: Union[Annotated[Literal["tool1"], Field(description="...")], ...]
literals = [
Annotated[Literal[tool.name], Field(description=tool.description)] for tool in tools
]
selected_tool_type = Union[tuple(literals)] # type: ignore[valid-type] # noqa: UP007
description = "Tools to use. Place the most relevant tools first."
class ToolSelectionResponse(TypedDict):
"""Use to select relevant tools."""
tools: Annotated[list[selected_tool_type], Field(description=description)] # type: ignore[valid-type]
return TypeAdapter(ToolSelectionResponse)
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _create_tool_selection_response() do?
_create_tool_selection_response() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/tool_selection.py.
Where is _create_tool_selection_response() defined?
_create_tool_selection_response() is defined in libs/langchain_v1/langchain/agents/middleware/tool_selection.py at line 47.
What calls _create_tool_selection_response()?
_create_tool_selection_response() is called by 2 function(s): awrap_model_call, wrap_model_call.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free