"""Main entrypoint for: {{ ir.name }}"""
# Generated by agent-blueprint {{ ir.version }}
# {{ ir.description or "" }}

import json
import sys
from langchain_core.messages import HumanMessage

from graph import graph


def run(user_input: str, thread_id: str = "default") -> str:
    """Run the agent with a user message and return the final response."""
    config = {"configurable": {"thread_id": thread_id}}
    result = graph.invoke(
        {"messages": [HumanMessage(content=user_input)]},
        config=config,
    )
    messages = result.get("messages", [])
    if messages:
        return messages[-1].content
    return ""


if __name__ == "__main__":
    if len(sys.argv) > 1:
        user_input = " ".join(sys.argv[1:])
    else:
        user_input = input("Enter your message: ")

    response = run(user_input)
    print(response)
