_consolidate_calls() — langchain Function Reference
Architecture documentation for the _consolidate_calls() function in _compat.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD d2907510_6a85_68c1_c20d_e21ea9422b36["_consolidate_calls()"] 92333051_7f77_b57b_d874_abb7bac2bbe0["_compat.py"] d2907510_6a85_68c1_c20d_e21ea9422b36 -->|defined in| 92333051_7f77_b57b_d874_abb7bac2bbe0 debfdf1e_2d5b_2867_c955_09be2be39501["_convert_from_v1_to_responses()"] debfdf1e_2d5b_2867_c955_09be2be39501 -->|calls| d2907510_6a85_68c1_c20d_e21ea9422b36 style d2907510_6a85_68c1_c20d_e21ea9422b36 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/openai/langchain_openai/chat_models/_compat.py lines 262–400
def _consolidate_calls(items: Iterable[dict[str, Any]]) -> Iterator[dict[str, Any]]:
"""Generator that walks through *items* and, whenever it meets the pair.
{"type": "server_tool_call", "name": "web_search", "id": X, ...}
{"type": "server_tool_result", "id": X}
merges them into
{"id": X,
"output": ...,
"status": ...,
"type": "web_search_call"}
keeping every other element untouched.
"""
items = iter(items) # make sure we have a true iterator
for current in items:
# Only a call can start a pair worth collapsing
if current.get("type") != "server_tool_call":
yield current
continue
try:
nxt = next(items) # look-ahead one element
except StopIteration: # no “result” - just yield the call back
yield current
break
# If this really is the matching “result” - collapse
if nxt.get("type") == "server_tool_result" and nxt.get(
"tool_call_id"
) == current.get("id"):
if current.get("name") == "web_search":
collapsed = {"id": current["id"]}
if "args" in current:
# N.B. as of 2025-09-17 OpenAI raises BadRequestError if sources
# are passed back in
collapsed["action"] = current["args"]
if status := nxt.get("status"):
if status == "success":
collapsed["status"] = "completed"
elif status == "error":
collapsed["status"] = "failed"
elif nxt.get("extras", {}).get("status"):
collapsed["status"] = nxt["extras"]["status"]
else:
pass
collapsed["type"] = "web_search_call"
if current.get("name") == "file_search":
collapsed = {"id": current["id"]}
if "args" in current and "queries" in current["args"]:
collapsed["queries"] = current["args"]["queries"]
if "output" in nxt:
collapsed["results"] = nxt["output"]
if status := nxt.get("status"):
if status == "success":
collapsed["status"] = "completed"
elif status == "error":
collapsed["status"] = "failed"
elif nxt.get("extras", {}).get("status"):
collapsed["status"] = nxt["extras"]["status"]
else:
pass
collapsed["type"] = "file_search_call"
elif current.get("name") == "code_interpreter":
collapsed = {"id": current["id"]}
if "args" in current and "code" in current["args"]:
collapsed["code"] = current["args"]["code"]
for key in ("container_id",):
if key in current:
collapsed[key] = current[key]
elif key in current.get("extras", {}):
collapsed[key] = current["extras"][key]
else:
pass
if "output" in nxt:
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _consolidate_calls() do?
_consolidate_calls() is a function in the langchain codebase, defined in libs/partners/openai/langchain_openai/chat_models/_compat.py.
Where is _consolidate_calls() defined?
_consolidate_calls() is defined in libs/partners/openai/langchain_openai/chat_models/_compat.py at line 262.
What calls _consolidate_calls()?
_consolidate_calls() is called by 1 function(s): _convert_from_v1_to_responses.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free