Files
task-6a02e23da6fe2e4ac16acf65/agent.py
T
2026-05-28 09:15:15 +00:00

40 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
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())