Kai Jennissen
commited on
add agent.py
Browse files
agent.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from smolagents import (
|
2 |
+
ToolCallingAgent,
|
3 |
+
CodeAgent,
|
4 |
+
DuckDuckGoSearchTool,
|
5 |
+
VisitWebpageTool,
|
6 |
+
InferenceClientModel,
|
7 |
+
)
|
8 |
+
from dotenv import load_dotenv
|
9 |
+
|
10 |
+
load_dotenv()
|
11 |
+
|
12 |
+
|
13 |
+
def get_agent():
|
14 |
+
llm_qwen = InferenceClientModel(
|
15 |
+
model_id="Qwen/Qwen2.5-Coder-32B-Instruct", provider="together"
|
16 |
+
)
|
17 |
+
llm_deepseek = InferenceClientModel(
|
18 |
+
"deepseek-ai/DeepSeek-R1", provider="together", max_tokens=8096
|
19 |
+
)
|
20 |
+
|
21 |
+
web_agent = ToolCallingAgent(
|
22 |
+
tools=[DuckDuckGoSearchTool(), VisitWebpageTool()],
|
23 |
+
model=llm_qwen,
|
24 |
+
max_steps=10,
|
25 |
+
name="Web_Agent",
|
26 |
+
description="A web agent that can search the web and visit webpages.",
|
27 |
+
)
|
28 |
+
|
29 |
+
manager_agent = CodeAgent(
|
30 |
+
tools=[],
|
31 |
+
managed_agents=[web_agent],
|
32 |
+
model=llm_deepseek,
|
33 |
+
max_steps=10,
|
34 |
+
)
|
35 |
+
return manager_agent
|
36 |
+
|
37 |
+
|
38 |
+
if __name__ == "__main__":
|
39 |
+
agent = get_agent()
|
40 |
+
agent.run(
|
41 |
+
"What is the latest news about AI? Please search the web and summarize the results."
|
42 |
+
)
|
app.py
CHANGED
@@ -2,13 +2,6 @@ import os
|
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
import pandas as pd
|
5 |
-
from smolagents import (
|
6 |
-
ToolCallingAgent,
|
7 |
-
CodeAgent,
|
8 |
-
DuckDuckGoSearchTool,
|
9 |
-
HfApiModel,
|
10 |
-
VisitWebpageTool,
|
11 |
-
)
|
12 |
from dotenv import load_dotenv
|
13 |
import base64
|
14 |
from opentelemetry.sdk.trace import TracerProvider
|
@@ -16,6 +9,7 @@ from openinference.instrumentation.smolagents import SmolagentsInstrumentor
|
|
16 |
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
|
17 |
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
|
18 |
from opentelemetry import trace
|
|
|
19 |
|
20 |
load_dotenv()
|
21 |
|
@@ -56,23 +50,6 @@ SmolagentsInstrumentor().instrument(tracer_provider=trace_provider)
|
|
56 |
|
57 |
# --- Basic Agent Definition ---
|
58 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
59 |
-
def get_agent():
|
60 |
-
llm = HfApiModel(
|
61 |
-
model_id="Qwen/Qwen2.5-Coder-32B-Instruct", token=os.getenv("HF_TOKEN")
|
62 |
-
)
|
63 |
-
web_agent = ToolCallingAgent(
|
64 |
-
tools=[DuckDuckGoSearchTool(), VisitWebpageTool()],
|
65 |
-
model=llm,
|
66 |
-
max_steps=10,
|
67 |
-
description="A web agent that can search the web and visit webpages.",
|
68 |
-
)
|
69 |
-
|
70 |
-
manager_agent = CodeAgent(
|
71 |
-
tools=[web_agent],
|
72 |
-
model=llm,
|
73 |
-
max_steps=10,
|
74 |
-
)
|
75 |
-
return manager_agent
|
76 |
|
77 |
|
78 |
class BasicAgent:
|
|
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
from dotenv import load_dotenv
|
6 |
import base64
|
7 |
from opentelemetry.sdk.trace import TracerProvider
|
|
|
9 |
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
|
10 |
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
|
11 |
from opentelemetry import trace
|
12 |
+
from .agent import get_agent
|
13 |
|
14 |
load_dotenv()
|
15 |
|
|
|
50 |
|
51 |
# --- Basic Agent Definition ---
|
52 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
|
55 |
class BasicAgent:
|