ai-agent / agent.py
Ayushi4's picture
Update agent.py
376f33e verified
Raw
History Blame Contribute Delete
933 Bytes
from langchain_groq import ChatGroq
from langchain.agents import AgentExecutor, create_react_agent
from langchain.memory import ConversationBufferWindowMemory
from langchain import hub
from tools import tools
import os
from dotenv import load_dotenv
load_dotenv()
def create_agent():
llm = ChatGroq(
groq_api_key="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",
model_name="llama-3.3-70b-versatile",
temperature=0.1,
max_tokens=2048
)
memory = ConversationBufferWindowMemory(
memory_key="chat_history",
k=5,
return_messages=True
)
prompt = hub.pull("hwchase17/react-chat")
agent = create_react_agent(llm, tools, prompt)
agent_executor = AgentExecutor(
agent=agent,
tools=tools,
memory=memory,
verbose=True,
max_iterations=5,
handle_parsing_errors=True
)
return agent_executor