Files
prakticheskoe-zadanie-agent…/src/agent.py
T

31 lines
1.0 KiB
Python

from langchain_ollama import Ollama
from langchain.agents import initialize_agent, AgentExecutor, AgentType
from langchain.tools import BaseTool
from typing import List
def create_agent(tools: List[BaseTool]) -> AgentExecutor:
"""
Create a LangChain agent that can use the provided tools.
Parameters:
tools (List[BaseTool]): List of tools for the agent.
Returns:
AgentExecutor: Configured agent.
"""
llm = Ollama(model="llama3")
system_prompt = (
"You are an AI assistant with access to a knowledge base. "
"Use the following tools to answer user queries:\n"
"- search_knowledge_base: Search the knowledge base.\n"
"- add_to_knowledge_base: Add a new document to the knowledge base.\n"
"When you need to use a tool, call it with the appropriate arguments."
)
agent = initialize_agent(
tools=tools,
llm=llm,
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
verbose=True,
agent_kwargs={"system_message": system_prompt},
)
return agent