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