33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
from langchain_core.messages import HumanMessage, AIMessage
|
|
from langgraph.graph import StateGraph, MessagesState, START, END
|
|
from ..backend import llm
|
|
|
|
def call_llama_server(state: MessagesState):
|
|
"""Call the local llama-server with the configured model using LangChain."""
|
|
# Get the last user message
|
|
messages = state["messages"]
|
|
if not messages:
|
|
return {"messages": [AIMessage(content="No message provided")]}
|
|
|
|
# Get the content of the last message
|
|
last_message = messages[-1]
|
|
user_content = last_message.content
|
|
|
|
# Invoke the LLM with the user message
|
|
response = llm.invoke(user_content)
|
|
|
|
return {"messages": [response]}
|
|
|
|
|
|
def create_agent_graph():
|
|
"""Create a simple agent graph that processes messages and calls the llama server."""
|
|
|
|
# Build the LangGraph workflow
|
|
graph = StateGraph(MessagesState)
|
|
graph.add_node(call_llama_server)
|
|
graph.add_edge(START, "call_llama_server")
|
|
graph.add_edge("call_llama_server", END)
|
|
graph = graph.compile()
|
|
|
|
return graph
|