""" 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())