From 3acd0b67f452e590fa86d2f61f003bb72a70629e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=9A=D1=83=D1=82?= =?UTF-8?q?=D0=BB=D0=B0=D1=85=D0=BC=D0=B5=D1=82=D0=BE=D0=B2?= Date: Thu, 28 May 2026 09:15:15 +0000 Subject: [PATCH] Add agent.py --- agent.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 agent.py diff --git a/agent.py b/agent.py new file mode 100644 index 0000000..8628897 --- /dev/null +++ b/agent.py @@ -0,0 +1,39 @@ +""" +Agent definition using LangChain create_agent. +""" + +import os +from langchain_openai import ChatOpenAI +from langchain.agents import create_agent +from langchain_core.messages import HumanMessage +from tools import search_knowledge_base, add_to_knowledge_base + +# LLM – Ollama via BroJS endpoint (placeholder) +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, +) + +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.", +) + +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) + +if __name__ == "__main__": # pragma: no cover + import asyncio + asyncio.run(main())