Commit ·
af6fdc2
1
Parent(s): a654024
fixed agent architecture
Browse files
agent.py
CHANGED
|
@@ -147,6 +147,8 @@ class BasicAgent:
|
|
| 147 |
self.hf_model_provider = hf_model_provider
|
| 148 |
self.tools_list = tools_list
|
| 149 |
print("BasicAgent initialized.")
|
|
|
|
|
|
|
| 150 |
|
| 151 |
def build_llm_with_tools(self):
|
| 152 |
print("Building Hugging Face model and tools...")
|
|
@@ -156,7 +158,7 @@ class BasicAgent:
|
|
| 156 |
provider=self.hf_model_provider,
|
| 157 |
max_new_tokens=8192,
|
| 158 |
do_sample=False,
|
| 159 |
-
temperature=0.
|
| 160 |
)
|
| 161 |
|
| 162 |
chat_model = ChatHuggingFace(llm=llm)
|
|
@@ -166,7 +168,7 @@ class BasicAgent:
|
|
| 166 |
llm_with_tools = chat_model.bind_tools(
|
| 167 |
self.tools_list
|
| 168 |
)
|
| 169 |
-
print("
|
| 170 |
return llm_with_tools
|
| 171 |
|
| 172 |
def build_agent_graph(self):
|
|
@@ -187,14 +189,14 @@ class BasicAgent:
|
|
| 187 |
tools_condition,
|
| 188 |
)
|
| 189 |
builder.add_edge("tools", "assistant")
|
| 190 |
-
|
|
|
|
|
|
|
| 191 |
|
| 192 |
async def __call__(self, question: str) -> str:
|
| 193 |
print(f"Agent received question (first 100 chars): {question[:100]}...")
|
| 194 |
# fixed_answer = "This is a default answer."
|
| 195 |
# print(f"Agent returning fixed answer: {fixed_answer}")
|
| 196 |
-
# Create agent with all the tools
|
| 197 |
-
agent_graph = self.build_agent_graph()
|
| 198 |
# Example query agent might receive
|
| 199 |
# fixed_answer = await agent.run(question)
|
| 200 |
messages = [
|
|
@@ -204,7 +206,7 @@ class BasicAgent:
|
|
| 204 |
content=question # + '/nothink'
|
| 205 |
)
|
| 206 |
]
|
| 207 |
-
response = await agent_graph.ainvoke(
|
| 208 |
{"messages": messages},
|
| 209 |
config={
|
| 210 |
"recursion_limit": 8,
|
|
|
|
| 147 |
self.hf_model_provider = hf_model_provider
|
| 148 |
self.tools_list = tools_list
|
| 149 |
print("BasicAgent initialized.")
|
| 150 |
+
# Create agent with all the tools
|
| 151 |
+
self.agent_graph = self.build_agent_graph()
|
| 152 |
|
| 153 |
def build_llm_with_tools(self):
|
| 154 |
print("Building Hugging Face model and tools...")
|
|
|
|
| 158 |
provider=self.hf_model_provider,
|
| 159 |
max_new_tokens=8192,
|
| 160 |
do_sample=False,
|
| 161 |
+
temperature=0.2,
|
| 162 |
)
|
| 163 |
|
| 164 |
chat_model = ChatHuggingFace(llm=llm)
|
|
|
|
| 168 |
llm_with_tools = chat_model.bind_tools(
|
| 169 |
self.tools_list
|
| 170 |
)
|
| 171 |
+
print("LLM with tools built successfully.")
|
| 172 |
return llm_with_tools
|
| 173 |
|
| 174 |
def build_agent_graph(self):
|
|
|
|
| 189 |
tools_condition,
|
| 190 |
)
|
| 191 |
builder.add_edge("tools", "assistant")
|
| 192 |
+
agent_graph = builder.compile()
|
| 193 |
+
print("Agent graph built successfully.")
|
| 194 |
+
return agent_graph
|
| 195 |
|
| 196 |
async def __call__(self, question: str) -> str:
|
| 197 |
print(f"Agent received question (first 100 chars): {question[:100]}...")
|
| 198 |
# fixed_answer = "This is a default answer."
|
| 199 |
# print(f"Agent returning fixed answer: {fixed_answer}")
|
|
|
|
|
|
|
| 200 |
# Example query agent might receive
|
| 201 |
# fixed_answer = await agent.run(question)
|
| 202 |
messages = [
|
|
|
|
| 206 |
content=question # + '/nothink'
|
| 207 |
)
|
| 208 |
]
|
| 209 |
+
response = await self.agent_graph.ainvoke(
|
| 210 |
{"messages": messages},
|
| 211 |
config={
|
| 212 |
"recursion_limit": 8,
|
app.py
CHANGED
|
@@ -9,7 +9,6 @@ import re
|
|
| 9 |
|
| 10 |
from tools import fetch_website, get_wiki_full, youtube_transcript, python_repl_tool, duckduckgo_search_results
|
| 11 |
|
| 12 |
-
|
| 13 |
# (Keep Constants as is)
|
| 14 |
# --- Constants ---
|
| 15 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
|
|
| 9 |
|
| 10 |
from tools import fetch_website, get_wiki_full, youtube_transcript, python_repl_tool, duckduckgo_search_results
|
| 11 |
|
|
|
|
| 12 |
# (Keep Constants as is)
|
| 13 |
# --- Constants ---
|
| 14 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|