Duibonduil commited on
Commit
d325251
·
verified ·
1 Parent(s): f78dcb7

Upload run.py

Browse files
Files changed (1) hide show
  1. examples/search/run.py +66 -0
examples/search/run.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding: utf-8
2
+ # Copyright (c) 2025 inclusionAI.
3
+
4
+ from aworld.agents.llm_agent import Agent
5
+ from aworld.config.conf import AgentConfig
6
+ from aworld.core.agent.swarm import Swarm
7
+ from aworld.runner import Runners
8
+ from examples.tools.common import Tools
9
+
10
+ search_sys_prompt = "You are a helpful search agent."
11
+ search_prompt = """
12
+ Please act as a search agent, constructing appropriate keywords and searach terms, using search toolkit to collect relevant information, including urls, webpage snapshots, etc.
13
+
14
+ Here are the question: {task}
15
+
16
+ pleas only use one action complete this task, at least results 6 pages.
17
+ """
18
+
19
+ summary_sys_prompt = "You are a helpful general summary agent."
20
+
21
+ summary_prompt = """
22
+ Summarize the following text in one clear and concise paragraph, capturing the key ideas without missing critical points.
23
+ Ensure the summary is easy to understand and avoids excessive detail.
24
+
25
+ Here are the content:
26
+ {task}
27
+ """
28
+
29
+ # search and summary
30
+ if __name__ == "__main__":
31
+ # need to set GOOGLE_API_KEY and GOOGLE_ENGINE_ID to use Google search.
32
+ # os.environ['GOOGLE_API_KEY'] = ""
33
+ # os.environ['GOOGLE_ENGINE_ID'] = ""
34
+
35
+ agent_config = AgentConfig(
36
+ llm_provider="openai",
37
+ llm_model_name="gpt-4o",
38
+ llm_temperature=1,
39
+ # need to set llm_api_key for use LLM
40
+ )
41
+
42
+ search = Agent(
43
+ conf=agent_config,
44
+ name="search_agent",
45
+ system_prompt=search_sys_prompt,
46
+ agent_prompt=search_prompt,
47
+ tool_names=[Tools.SEARCH_API.value]
48
+ )
49
+
50
+ summary = Agent(
51
+ conf=agent_config,
52
+ name="summary_agent",
53
+ system_prompt=summary_sys_prompt,
54
+ agent_prompt=summary_prompt
55
+ )
56
+ # default is workflow swarm
57
+ swarm = Swarm(search, summary, max_steps=1)
58
+
59
+ prefix = ""
60
+ # can special search google, wiki, duck go, or baidu. such as:
61
+ # prefix = "search wiki: "
62
+ res = Runners.sync_run(
63
+ input=prefix + """What is an agent.""",
64
+ swarm=swarm
65
+ )
66
+ print(res.answer)