Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files
examples/cmd/agent_deploy/demo_agent/__init__.py
ADDED
File without changes
|
examples/cmd/agent_deploy/demo_agent/agent.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
+
import os
|
3 |
+
import json
|
4 |
+
from aworld.cmd import BaseAWorldAgent, ChatCompletionRequest
|
5 |
+
from aworld.config.conf import AgentConfig, TaskConfig
|
6 |
+
from aworld.agents.llm_agent import Agent
|
7 |
+
from aworld.core.task import Task
|
8 |
+
from aworld.runner import Runners
|
9 |
+
|
10 |
+
logger = logging.getLogger(__name__)
|
11 |
+
|
12 |
+
|
13 |
+
class AWorldAgent(BaseAWorldAgent):
|
14 |
+
def __init__(self, *args, **kwargs):
|
15 |
+
super().__init__(*args, **kwargs)
|
16 |
+
|
17 |
+
def name(self):
|
18 |
+
return "Demo Agent"
|
19 |
+
|
20 |
+
def description(self):
|
21 |
+
return "Demo Agent with fetch and time mcp server"
|
22 |
+
|
23 |
+
async def run(self, prompt: str = None, request: ChatCompletionRequest = None):
|
24 |
+
llm_provider = os.getenv("LLM_PROVIDER_DEMO", "openai")
|
25 |
+
llm_model_name = os.getenv("LLM_MODEL_NAME_DEMO")
|
26 |
+
llm_api_key = os.getenv("LLM_API_KEY_DEMO")
|
27 |
+
llm_base_url = os.getenv("LLM_BASE_URL_DEMO")
|
28 |
+
llm_temperature = os.getenv("LLM_TEMPERATURE_DEMO", 0.0)
|
29 |
+
|
30 |
+
if not llm_model_name or not llm_api_key or not llm_base_url:
|
31 |
+
raise ValueError(
|
32 |
+
"LLM_MODEL_NAME, LLM_API_KEY, LLM_BASE_URL must be set in your envrionment variables"
|
33 |
+
)
|
34 |
+
|
35 |
+
agent_config = AgentConfig(
|
36 |
+
llm_provider=llm_provider,
|
37 |
+
llm_model_name=llm_model_name,
|
38 |
+
llm_api_key=llm_api_key,
|
39 |
+
llm_base_url=llm_base_url,
|
40 |
+
llm_temperature=llm_temperature,
|
41 |
+
)
|
42 |
+
|
43 |
+
path_cwd = os.path.dirname(os.path.abspath(__file__))
|
44 |
+
mcp_path = os.path.join(path_cwd, "mcp.json")
|
45 |
+
with open(mcp_path, "r") as f:
|
46 |
+
mcp_config = json.load(f)
|
47 |
+
|
48 |
+
super_agent = Agent(
|
49 |
+
conf=agent_config,
|
50 |
+
name="🙋🏻♂️ Demo Agent",
|
51 |
+
system_prompt="You are a demo agent, you can query current time and fetch data from the internet. you must use search engine to get url, then fetch data from the url, don't use url don't exist.",
|
52 |
+
mcp_config=mcp_config,
|
53 |
+
mcp_servers=mcp_config.get("mcpServers", {}).keys(),
|
54 |
+
)
|
55 |
+
|
56 |
+
if prompt is None and request is not None:
|
57 |
+
prompt = request.messages[-1].content
|
58 |
+
|
59 |
+
task = Task(
|
60 |
+
input=prompt,
|
61 |
+
agent=super_agent,
|
62 |
+
conf=TaskConfig(max_steps=20),
|
63 |
+
)
|
64 |
+
|
65 |
+
async for output in Runners.streamed_run_task(task).stream_events():
|
66 |
+
logger.info(f"Agent Ouput: {output}")
|
67 |
+
yield output
|
examples/cmd/agent_deploy/demo_agent/mcp.json
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"mcpServers": {
|
3 |
+
"google-pse-search": {
|
4 |
+
"command": "npx",
|
5 |
+
"args": [
|
6 |
+
"-y",
|
7 |
+
"@adenot/mcp-google-search"
|
8 |
+
],
|
9 |
+
"env": {
|
10 |
+
"GOOGLE_API_KEY": "${GOOGLE_API_KEY}",
|
11 |
+
"GOOGLE_SEARCH_ENGINE_ID": "${GOOGLE_SEARCH_ENGINE_ID}"
|
12 |
+
}
|
13 |
+
},
|
14 |
+
"fetch": {
|
15 |
+
"command": "uvx",
|
16 |
+
"args": [
|
17 |
+
"-i",
|
18 |
+
"https://mirrors.aliyun.com/pypi/simple/",
|
19 |
+
"mcp-server-fetch",
|
20 |
+
"--ignore-robots-txt"
|
21 |
+
]
|
22 |
+
},
|
23 |
+
"time": {
|
24 |
+
"command": "uvx",
|
25 |
+
"args": [
|
26 |
+
"mcp-server-time",
|
27 |
+
"--local-timezone",
|
28 |
+
"Asia/Shanghai"
|
29 |
+
]
|
30 |
+
}
|
31 |
+
}
|
32 |
+
}
|
examples/cmd/agent_deploy/demo_agent/requirements.txt
ADDED
File without changes
|