def with_agent_name(
    model: LanguageModelLike,
    agent_name_mode: AgentNameMode,
) -> LanguageModelLike:
    """Attach formatted agent names to the messages passed to and from a language model.

    This is useful for making a message history with multiple agents more coherent.

    NOTE: agent name is consumed from the message.name field.
        If you're using an agent built with create_react_agent, name is automatically set.
        If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.

    Args:
        model: Language model to add agent name formatting to.
        agent_name_mode: Use to specify how to expose the agent name to the LLM.
            - "inline": Add the agent name directly into the content field of the AI message using XML-style tags.
                Example: "How can I help you" -> "<name>agent_name</name><content>How can I help you?</content>".
    """
    if agent_name_mode == "inline":
        process_input_message = add_inline_agent_name
        process_output_message = remove_inline_agent_name
    else:
        raise ValueError(
            f"Invalid agent name mode: {agent_name_mode}. Needs to be one of: {AgentNameMode.__args__}"
        )

    def process_input_messages(
        input: Sequence[MessageLikeRepresentation] | PromptValue,
    ) -> list[BaseMessage]:
        messages = convert_to_messages(input)
        return [process_input_message(message) for message in messages]

    chain = (
        process_input_messages
        | model
        | RunnableLambda(process_output_message, name="process_output_message")
    )

    return cast(LanguageModelLike, chain)
Attach formatted agent names to the messages passed to and from a language model.

    This is useful for making a message history with multiple agents more coherent.

    NOTE: agent name is consumed from the message.name field.
        If you're using an agent built with create_react_agent, name is automatically set.
        If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.

    Args:
        model: Language model to add agent name formatting to.
        agent_name_mode: Use to specify how to expose the agent name to the LLM.
            - "inline": Add the agent name directly into the content field of the AI message using XML-style tags.
                Example: "How can I help you" -> "<name>agent_name</name><content>How can I help you?</content>".
    
langgraph_supervisor/agent_name.py