Home / Function/ init_server_tool_calls() — langchain Function Reference

init_server_tool_calls() — langchain Function Reference

Architecture documentation for the init_server_tool_calls() function in ai.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  40233daa_394a_ac86_26c9_2c171e53c578["init_server_tool_calls()"]
  0998183a_ee20_cc02_d37b_948998ae74b7["AIMessageChunk"]
  40233daa_394a_ac86_26c9_2c171e53c578 -->|defined in| 0998183a_ee20_cc02_d37b_948998ae74b7
  style 40233daa_394a_ac86_26c9_2c171e53c578 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/messages/ai.py lines 590–616

    def init_server_tool_calls(self) -> Self:
        """Initialize server tool calls.

        Parse `server_tool_call_chunks` from
        [`ServerToolCallChunk`][langchain.messages.ServerToolCallChunk] objects.
        """
        if (
            self.chunk_position == "last"
            and self.response_metadata.get("output_version") == "v1"
            and isinstance(self.content, list)
        ):
            for idx, block in enumerate(self.content):
                if (
                    isinstance(block, dict)
                    and block.get("type")
                    in {"server_tool_call", "server_tool_call_chunk"}
                    and (args_str := block.get("args"))
                    and isinstance(args_str, str)
                ):
                    try:
                        args = json.loads(args_str)
                        if isinstance(args, dict):
                            self.content[idx]["type"] = "server_tool_call"  # type: ignore[index]
                            self.content[idx]["args"] = args  # type: ignore[index]
                    except json.JSONDecodeError:
                        pass
        return self

Domain

Subdomains

Frequently Asked Questions

What does init_server_tool_calls() do?
init_server_tool_calls() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/ai.py.
Where is init_server_tool_calls() defined?
init_server_tool_calls() is defined in libs/core/langchain_core/messages/ai.py at line 590.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free