diff --git a/agent.py b/agent.py index 8628897..7233f37 100644 --- a/agent.py +++ b/agent.py @@ -1,39 +1,31 @@ """ -Agent definition using LangChain create_agent. +Agent creation with RAG integration. """ - import os +from typing import List + from langchain_openai import ChatOpenAI from langchain.agents import create_agent from langchain_core.messages import HumanMessage +from langgraph.checkpoint.memory import MemorySaver from tools import search_knowledge_base, add_to_knowledge_base -# LLM – Ollama via BroJS endpoint (placeholder) +# LLM via Ollama (llama3) llm = ChatOpenAI( - model="openai/gpt-oss-20b:free", - base_url="https://platform.brojs.ru/jrnl-bh/api/inference/v1", - api_key=os.getenv("JOURNAL_MCP_PAT"), - temperature=0.5, + model="ollama/llama3", + base_url="http://localhost:11434/v1", + api_key=None, + temperature=0.2, ) agent = create_agent( llm=llm, tools=[search_knowledge_base, add_to_knowledge_base], - system_prompt="You are a helpful assistant with access to a knowledge base.", + system_prompt="You are a helpful assistant that can search and add documents to the knowledge base.", ) -async def main(): - # Simple demo: add and search - await agent.ainvoke( - {"messages": [HumanMessage(content="Add sample text about Python")]}, - {"configurable": {"thread_id": "demo-1"}}, - ) - result = await agent.ainvoke( - {"messages": [HumanMessage(content="Search for Python")]}, - {"configurable": {"thread_id": "demo-1"}}, - ) - print(result["messages"][-1].content) +memory = MemorySaver() -if __name__ == "__main__": # pragma: no cover - import asyncio - asyncio.run(main()) +async def run_agent(messages: List[HumanMessage]): + result = await agent.ainvoke({"messages": messages}, {"configurable": {"thread_id": "session-1"}}) + return result["messages"][-1].content