Home / Function/ wrap_model_call() — langchain Function Reference

wrap_model_call() — langchain Function Reference

Architecture documentation for the wrap_model_call() function in todo.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  599153ad_dee9_927c_45d6_fb594a726e10["wrap_model_call()"]
  60552546_6c10_6b0f_fd5d_93ed6530c806["TodoListMiddleware"]
  599153ad_dee9_927c_45d6_fb594a726e10 -->|defined in| 60552546_6c10_6b0f_fd5d_93ed6530c806
  style 599153ad_dee9_927c_45d6_fb594a726e10 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/langchain/agents/middleware/todo.py lines 201–226

    def wrap_model_call(
        self,
        request: ModelRequest[ContextT],
        handler: Callable[[ModelRequest[ContextT]], ModelResponse[ResponseT]],
    ) -> ModelResponse[ResponseT] | AIMessage:
        """Update the system message to include the todo system prompt.

        Args:
            request: Model request to execute (includes state and runtime).
            handler: Async callback that executes the model request and returns
                `ModelResponse`.

        Returns:
            The model call result.
        """
        if request.system_message is not None:
            new_system_content = [
                *request.system_message.content_blocks,
                {"type": "text", "text": f"\n\n{self.system_prompt}"},
            ]
        else:
            new_system_content = [{"type": "text", "text": self.system_prompt}]
        new_system_message = SystemMessage(
            content=cast("list[str | dict[str, str]]", new_system_content)
        )
        return handler(request.override(system_message=new_system_message))

Domain

Subdomains

Frequently Asked Questions

What does wrap_model_call() do?
wrap_model_call() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/todo.py.
Where is wrap_model_call() defined?
wrap_model_call() is defined in libs/langchain_v1/langchain/agents/middleware/todo.py at line 201.

Analyze Your Own Codebase

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

Try Supermodel Free