Duibonduil commited on
Commit
e24d336
·
verified ·
1 Parent(s): 87f577c

Upload 5 files

Browse files
examples/cmd/agent_deploy/team_agent/__init__.py ADDED
File without changes
examples/cmd/agent_deploy/team_agent/agent.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.agent.swarm import Swarm
8
+ from aworld.core.task import Task
9
+ from aworld.runner import Runners
10
+ from examples.plan_execute.agent import PlanAgent
11
+ from .prompt import *
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ class AWorldAgent(BaseAWorldAgent):
17
+ def __init__(self, *args, **kwargs):
18
+ super().__init__(*args, **kwargs)
19
+
20
+ def name(self):
21
+ return "Team Agent"
22
+
23
+ def description(self):
24
+ return "Team Agent with fetch and time mcp server"
25
+
26
+ async def run(self, prompt: str = None, request: ChatCompletionRequest = None):
27
+ llm_provider = os.getenv("LLM_PROVIDER_TEAM", "openai")
28
+ llm_model_name = os.getenv("LLM_MODEL_NAME_TEAM")
29
+ llm_api_key = os.getenv("LLM_API_KEY_TEAM")
30
+ llm_base_url = os.getenv("LLM_BASE_URL_TEAM")
31
+ llm_temperature = os.getenv("LLM_TEMPERATURE_TEAM", 0.0)
32
+
33
+ if not llm_model_name or not llm_api_key or not llm_base_url:
34
+ raise ValueError(
35
+ "LLM_MODEL_NAME, LLM_API_KEY, LLM_BASE_URL must be set in your envrionment variables"
36
+ )
37
+
38
+ agent_config = AgentConfig(
39
+ llm_provider=llm_provider,
40
+ llm_model_name=llm_model_name,
41
+ llm_api_key=llm_api_key,
42
+ llm_base_url=llm_base_url,
43
+ llm_temperature=llm_temperature,
44
+ )
45
+
46
+ path_cwd = os.path.dirname(os.path.abspath(__file__))
47
+ mcp_path = os.path.join(path_cwd, "mcp.json")
48
+ with open(mcp_path, "r") as f:
49
+ mcp_config = json.load(f)
50
+
51
+ plan_agent = PlanAgent(name="🙋🏻‍♂️ Team Agent Demo", conf=agent_config)
52
+
53
+ search_agent = Agent(
54
+ conf=agent_config,
55
+ name="🔎 Search Agent",
56
+ system_prompt=search_sys_prompt,
57
+ agent_prompt=search_agent_prompt,
58
+ mcp_config=mcp_config,
59
+ mcp_servers=mcp_config.get("mcpServers", {}).keys(),
60
+ )
61
+
62
+ summary_agent = Agent(
63
+ conf=agent_config,
64
+ name="💬 Summary Agent",
65
+ system_prompt=summary_sys_prompt,
66
+ agent_prompt=summary_agent_prompt,
67
+ )
68
+
69
+ output_agent = Agent(
70
+ conf=agent_config,
71
+ name="💬 Output Agent",
72
+ system_prompt=output_sys_prompt,
73
+ agent_prompt=output_agent_prompt,
74
+ mcp_config=mcp_config,
75
+ mcp_servers=mcp_config.get("mcpServers", {}).keys(),
76
+ )
77
+
78
+ # default is sequence swarm mode
79
+ swarm = Swarm(
80
+ plan_agent, search_agent, summary_agent, output_agent, max_steps=10
81
+ )
82
+
83
+ if prompt is None and request is not None:
84
+ prompt = request.messages[-1].content
85
+
86
+ task = Task(
87
+ input=prompt,
88
+ swarm=swarm,
89
+ conf=TaskConfig(max_steps=20),
90
+ )
91
+
92
+ async for output in Runners.streamed_run_task(task).stream_events():
93
+ logger.info(f"Agent Ouput: {output}")
94
+ yield output
examples/cmd/agent_deploy/team_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/team_agent/prompt.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ search_sys_prompt = "YOU MUST SAY: 'Search Agent System Prompt'"
2
+
3
+ search_agent_prompt = "YOU MUST SAY: 'Search Agent Prompt'"
4
+
5
+ summary_sys_prompt = "YOU MUST SAY: 'Summary Agent System Prompt'"
6
+
7
+ summary_agent_prompt = "YOU MUST SAY: 'Summary Agent Prompt'"
8
+
9
+
10
+ output_sys_prompt = "YOU MUST SAY: 'Output Agent System Prompt'"
11
+
12
+
13
+ output_agent_prompt = "YOU MUST SAY: 'Output Agent Prompt'"
examples/cmd/agent_deploy/team_agent/requirements.txt ADDED
File without changes