-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
28 lines (24 loc) · 974 Bytes
/
agent.py
File metadata and controls
28 lines (24 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# agent.py
from langchain.agents import initialize_agent, AgentType
from langchain_ollama import OllamaLLM
from tools import tools
# Initialize the LLM (Qwen2.5-7B via Ollama)
llm = OllamaLLM(model="qwen2.5")
# Initialize the agent
agent = initialize_agent(
tools=tools,
llm=llm,
agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
verbose=True,
handle_parsing_errors=True
)
# Function to run queries
def run_agent_query(query):
try:
response = agent.invoke({"input": query})["output"]
return response
except Exception as e:
return f"Agent error: {str(e)}"
if __name__ == "__main__":
print(run_agent_query('List .py files in ./my_project using file_operations with input {"action": "list", "file_path": "./my_project"}'))
print(run_agent_query('Read ./docs/report.txt using file_operations with input {"action": "read", "file_path": "./docs/report.txt"} and tell me the project goal'))