"""Inspect context assembly, not model recall or tokenization. No inference call."""

from langchain_core.messages import AIMessage, HumanMessage
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder, PromptTemplate
from langsmith import tracing_context


def main():
    prompt = ChatPromptTemplate.from_messages([
        ("system", "Answer from the supplied conversation. If the name is absent, say unknown."),
        MessagesPlaceholder("history"),
        ("human", "{question}"),
    ])
    history = [HumanMessage(content="My name is Mina."), AIMessage(content="Hello, Mina.")]
    with tracing_context(enabled=False):
        with_history = prompt.invoke({"history": history, "question": "What is my name?"}).to_messages()
        without_history = prompt.invoke({"history": [], "question": "What is my name?"}).to_messages()
        plain = PromptTemplate.from_template("System: {instruction}").invoke({"instruction": "Be concise."}).to_messages()
    assert [m.type for m in with_history] == ["system", "human", "ai", "human"]
    assert [m.type for m in without_history] == ["system", "human"]
    assert any("Mina" in m.content for m in with_history)
    assert not any("Mina" in m.content for m in without_history)
    assert plain[0].type == "human", "A word in plain text does not create a system role."
    print("With history:", [m.type for m in with_history], "name present")
    print("Without history:", [m.type for m in without_history], "name absent")
    print("Plain text beginning 'System:' has message type:", plain[0].type)
    print("PASS: context inclusion, omission, and structured-role distinction.")
    print("No model inference or tokenizer was run; this does not measure recall quality.")


if __name__ == "__main__":
    main()
