Home / Function/ _build_commands() — langchain Function Reference

_build_commands() — langchain Function Reference

Architecture documentation for the _build_commands() function in factory.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  75a07fc9_a1f8_f785_227c_5009d6f748b3["_build_commands()"]
  fd7a28b1_3772_169b_6524_1342f35143b1["factory.py"]
  75a07fc9_a1f8_f785_227c_5009d6f748b3 -->|defined in| fd7a28b1_3772_169b_6524_1342f35143b1
  f4b66c38_651c_807a_caca_41f73fbbe516["create_agent()"]
  f4b66c38_651c_807a_caca_41f73fbbe516 -->|calls| 75a07fc9_a1f8_f785_227c_5009d6f748b3
  style 75a07fc9_a1f8_f785_227c_5009d6f748b3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/langchain/agents/factory.py lines 162–201

def _build_commands(
    model_response: ModelResponse,
    middleware_commands: list[Command[Any]] | None = None,
) -> list[Command[Any]]:
    """Build a list of Commands from a model response and middleware commands.

    The first Command contains the model response state (messages and optional
    structured_response). Middleware commands are appended as-is.

    Args:
        model_response: The model response containing messages and optional
            structured output.
        middleware_commands: Commands accumulated from middleware layers during
            composition (inner-first ordering).

    Returns:
        List of ``Command`` objects ready to be returned from a model node.
    """
    state: dict[str, Any] = {"messages": model_response.result}

    if model_response.structured_response is not None:
        state["structured_response"] = model_response.structured_response

    for cmd in middleware_commands or []:
        if cmd.goto:
            msg = (
                "Command goto is not yet supported in wrap_model_call middleware. "
                "Use the jump_to state field with before_model/after_model hooks instead."
            )
            raise NotImplementedError(msg)
        if cmd.resume:
            msg = "Command resume is not yet supported in wrap_model_call middleware."
            raise NotImplementedError(msg)
        if cmd.graph:
            msg = "Command graph is not yet supported in wrap_model_call middleware."
            raise NotImplementedError(msg)

    commands: list[Command[Any]] = [Command(update=state)]
    commands.extend(middleware_commands or [])
    return commands

Domain

Subdomains

Called By

Frequently Asked Questions

What does _build_commands() do?
_build_commands() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/factory.py.
Where is _build_commands() defined?
_build_commands() is defined in libs/langchain_v1/langchain/agents/factory.py at line 162.
What calls _build_commands()?
_build_commands() is called by 1 function(s): create_agent.

Analyze Your Own Codebase

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

Try Supermodel Free