Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -14,81 +14,72 @@ from smolagents import (
|
|
14 |
LogLevel
|
15 |
)
|
16 |
|
17 |
-
from smolagents.models import MLXModel
|
18 |
|
19 |
import re
|
20 |
import html
|
21 |
import datetime
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# Set up your model and logger
|
25 |
model = HfApiModel()
|
26 |
logger = AgentLogger(level=LogLevel.INFO)
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
# Create your agents
|
33 |
-
search_agent = ToolCallingAgent(
|
34 |
-
tools=[DuckDuckGoSearchTool(), VisitWebpageTool()],
|
35 |
-
model=model,
|
36 |
-
name="search_agent",
|
37 |
-
description="This is an agent that can do web search.",
|
38 |
-
max_steps=12,
|
39 |
-
verbosity_level=1
|
40 |
-
)
|
41 |
-
|
42 |
-
mentor_agent = ToolCallingAgent(
|
43 |
-
tools=[DuckDuckGoSearchTool(), VisitWebpageTool()],
|
44 |
-
model=model,
|
45 |
-
name="mentor_agent",
|
46 |
-
description="This is an agent that creates a persona of a mentor based on the hackathon idea and gives feedback.",
|
47 |
-
max_steps=12,
|
48 |
-
planning_interval=2,
|
49 |
-
verbosity_level=1
|
50 |
-
)
|
51 |
-
|
52 |
-
design_research_agent = ToolCallingAgent(
|
53 |
-
tools=[DuckDuckGoSearchTool(), VisitWebpageTool()],
|
54 |
model=model,
|
55 |
-
name="
|
56 |
-
description="
|
57 |
-
max_steps=12,
|
58 |
-
planning_interval=2,
|
59 |
-
verbosity_level=1
|
60 |
-
)
|
61 |
-
|
62 |
-
visual_design_agent = ToolCallingAgent(
|
63 |
-
tools=[image_generation_tool],
|
64 |
-
model=MLXModel(model_id="HuggingFaceTB/SmolLM-135M-Instruct"),
|
65 |
-
name="visual_design_agent",
|
66 |
-
description="Creates, reviews, and iterates on front-end mockups of product ideas",
|
67 |
max_steps=12,
|
68 |
-
|
69 |
-
|
70 |
)
|
71 |
|
72 |
-
|
73 |
# Create a manager agent that can create more agents
|
74 |
-
|
75 |
tools=[],
|
|
|
76 |
model=model,
|
77 |
-
|
78 |
-
|
79 |
-
description="This agent can solve problems using code and delegate to other agents when needed.",
|
80 |
max_steps=12,
|
81 |
verbosity_level=1,
|
82 |
planning_interval=4
|
83 |
)
|
84 |
|
85 |
|
|
|
86 |
# Capture agent visualization
|
87 |
-
|
88 |
-
buffer = io.StringIO()
|
89 |
-
with redirect_stdout(buffer):
|
90 |
-
logger.visualize_agent_tree(manager_agent)
|
91 |
-
return buffer.getvalue()
|
92 |
|
93 |
def clean_ansi_codes(text):
|
94 |
"""Remove ANSI color codes for clean display"""
|
@@ -161,6 +152,8 @@ class MonitoringGradioUI(GradioUI):
|
|
161 |
[text_input, file_uploads_log],
|
162 |
[stored_messages, text_input, submit_btn],
|
163 |
).then(self.interact_with_agent, [stored_messages, chatbot, session_state], [chatbot]).then(
|
|
|
|
|
164 |
lambda: (
|
165 |
gr.Textbox(
|
166 |
interactive=True, placeholder="Enter your prompt here and press Shift+Enter or the button"
|
@@ -187,30 +180,30 @@ class MonitoringGradioUI(GradioUI):
|
|
187 |
)
|
188 |
|
189 |
# Add the Monitoring tab
|
190 |
-
with gr.Tab("Agent Monitoring"):
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
|
200 |
-
|
201 |
|
202 |
-
|
203 |
-
|
204 |
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
|
213 |
-
|
214 |
|
215 |
# Add some explanatory text
|
216 |
gr.Markdown("""
|
@@ -231,5 +224,5 @@ class MonitoringGradioUI(GradioUI):
|
|
231 |
import os
|
232 |
os.makedirs("./uploads", exist_ok=True)
|
233 |
|
234 |
-
ui = MonitoringGradioUI(
|
235 |
ui.launch(share=True) # Set share=False if you don't want to create a public link
|
|
|
14 |
LogLevel
|
15 |
)
|
16 |
|
|
|
17 |
|
18 |
import re
|
19 |
import html
|
20 |
import datetime
|
21 |
|
22 |
+
def save_conversation_to_file(conversation, filename="~/data/final_negotiation.txt"):
|
23 |
+
os.makedirs(os.path.expanduser("~/data"), exist_ok=True)
|
24 |
+
full_path = os.path.expanduser(filename)
|
25 |
+
with open(full_path, "w") as f:
|
26 |
+
for msg in conversation:
|
27 |
+
f.write(f"{msg['role']}: {msg['content']}\n")
|
28 |
+
return full_path
|
29 |
+
|
30 |
+
import subprocess
|
31 |
+
|
32 |
+
def run_terminal_command(file_path):
|
33 |
+
command = [
|
34 |
+
"recall",
|
35 |
+
"bucket",
|
36 |
+
"add",
|
37 |
+
"--address", "0xff00000000000000000000000000000000000109",
|
38 |
+
"--key", "hello/world",
|
39 |
+
file_path
|
40 |
+
]
|
41 |
+
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
42 |
+
return result.stdout.decode(), result.stderr.decode()
|
43 |
+
|
44 |
+
def save_and_run(chat_history):
|
45 |
+
file_path = save_conversation_to_file(chat_history)
|
46 |
+
stdout, stderr = run_terminal_command(file_path)
|
47 |
+
print("Recall Output:", stdout)
|
48 |
+
if stderr:
|
49 |
+
print("Recall Error:", stderr)
|
50 |
+
return chat_history
|
51 |
+
|
52 |
|
53 |
# Set up your model and logger
|
54 |
model = HfApiModel()
|
55 |
logger = AgentLogger(level=LogLevel.INFO)
|
56 |
|
57 |
+
agent_party_b = CodeAgent(
|
58 |
+
tools=[],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
model=model,
|
60 |
+
name="agent_party_b",
|
61 |
+
description="You are Dr. Daniel Faraday's negotiation agent seeking favorable research terms for a physicist specializing in time-space anomalies; require research autonomy, equipment access, publication pathways, safety protocols, and return guarantees; prioritize unique research access over compensation; authorized to accept agreements meeting all non-negotiables and addressing 60 percent of key questions satisfactorily.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
max_steps=12,
|
63 |
+
verbosity_level=1,
|
64 |
+
planning_interval=4
|
65 |
)
|
66 |
|
|
|
67 |
# Create a manager agent that can create more agents
|
68 |
+
agent_party_a = CodeAgent(
|
69 |
tools=[],
|
70 |
+
managed_agents=[agent_party_b],
|
71 |
model=model,
|
72 |
+
name="agent_party_a",
|
73 |
+
description="Work with Dr. Daniel Faraday's Agent. You are Dr. Juliet Burke's negotiation agent seeking qualified researchers (PhD required, 6-month commitment, top-secret clearance) for confidential island medical research; prioritize security and minimal information disclosure while offering unique research opportunities, competitive compensation, and publication rights (with review); authorized to finalize agreements meeting all non-negotiables and 70 percent of strategic goals.",
|
|
|
74 |
max_steps=12,
|
75 |
verbosity_level=1,
|
76 |
planning_interval=4
|
77 |
)
|
78 |
|
79 |
|
80 |
+
|
81 |
# Capture agent visualization
|
82 |
+
|
|
|
|
|
|
|
|
|
83 |
|
84 |
def clean_ansi_codes(text):
|
85 |
"""Remove ANSI color codes for clean display"""
|
|
|
152 |
[text_input, file_uploads_log],
|
153 |
[stored_messages, text_input, submit_btn],
|
154 |
).then(self.interact_with_agent, [stored_messages, chatbot, session_state], [chatbot]).then(
|
155 |
+
save_and_run, [chatbot], [chatbot]
|
156 |
+
).then(
|
157 |
lambda: (
|
158 |
gr.Textbox(
|
159 |
interactive=True, placeholder="Enter your prompt here and press Shift+Enter or the button"
|
|
|
180 |
)
|
181 |
|
182 |
# Add the Monitoring tab
|
183 |
+
# with gr.Tab("Agent Monitoring"):
|
184 |
+
# # Get the visualization text
|
185 |
+
# agent_viz = get_agent_visualization()
|
186 |
+
# agent_viz_clean = clean_ansi_codes(agent_viz)
|
187 |
|
188 |
+
# # Convert the tree characters to HTML with proper formatting
|
189 |
+
# html_viz = agent_viz_clean.replace("βββ", "ββ ").replace("βββ", "ββ ").replace("β", "β ")
|
190 |
+
# html_viz = html.escape(html_viz)
|
191 |
+
# html_viz = f"<pre style='font-family: monospace; white-space: pre; font-size: 14px;'>{html_viz}</pre>"
|
192 |
|
193 |
+
# viz_html = gr.HTML(value=html_viz)
|
194 |
|
195 |
+
# # Add a refresh button
|
196 |
+
# refresh_btn = gr.Button("Refresh Agent Tree")
|
197 |
|
198 |
+
# def refresh_viz():
|
199 |
+
# new_viz = get_agent_visualization()
|
200 |
+
# new_viz_clean = clean_ansi_codes(new_viz)
|
201 |
+
# html_viz = new_viz_clean.replace("βββ", "ββ ").replace("βββ", "ββ ").replace("β", "β ")
|
202 |
+
# html_viz = html.escape(html_viz)
|
203 |
+
# html_viz = f"<pre style='font-family: monospace; white-space: pre; font-size: 14px;'>{html_viz}</pre>"
|
204 |
+
# return html_viz
|
205 |
|
206 |
+
# refresh_btn.click(refresh_viz, None, viz_html)
|
207 |
|
208 |
# Add some explanatory text
|
209 |
gr.Markdown("""
|
|
|
224 |
import os
|
225 |
os.makedirs("./uploads", exist_ok=True)
|
226 |
|
227 |
+
ui = MonitoringGradioUI(agent_party_a, file_upload_folder="./uploads")
|
228 |
ui.launch(share=True) # Set share=False if you don't want to create a public link
|