feat: solution for 'Практическое задание: Агент с RAG-памятью'
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
```python
|
||||
"""
|
||||
Agent creation with RAG integration.
|
||||
"""
|
||||
|
||||
from langchain.llms import Ollama
|
||||
from langchain.agents import initialize_agent, AgentType
|
||||
from langchain.tools import Tool
|
||||
|
||||
from tools import search_knowledge_base, add_to_knowledge_base
|
||||
|
||||
|
||||
def create_agent():
|
||||
"""
|
||||
Create and configure the LangChain agent.
|
||||
|
||||
Returns:
|
||||
AgentExecutor instance ready to run queries.
|
||||
"""
|
||||
llm = Ollama(model="llama3")
|
||||
|
||||
tools = [
|
||||
Tool.from_function(search_knowledge_base),
|
||||
Tool.from_function(add_to_knowledge_base),
|
||||
]
|
||||
|
||||
agent = initialize_agent(
|
||||
tools,
|
||||
llm,
|
||||
agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
|
||||
verbose=True,
|
||||
agent_kwargs={
|
||||
"system_message": (
|
||||
"You are an AI assistant that can search and add documents to a knowledge base. "
|
||||
"Use the provided tools to answer user queries."
|
||||
)
|
||||
},
|
||||
)
|
||||
return agent
|
||||
```
|
||||
Reference in New Issue
Block a user