Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- examples/travel/README.md +6 -0
- examples/travel/img.png +0 -0
- examples/travel/prompts.py +74 -0
- examples/travel/run.py +86 -0
examples/travel/README.md
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
Multi-agent interaction paradigm in travel examples.
|
3 |
+
|
4 |
+

|
5 |
+
|
6 |
+
Suggest using gpt-4o or deepseek-chat models, The latter does not support multimodality, so set use_vision to false.
|
examples/travel/img.png
ADDED
![]() |
examples/travel/prompts.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding: utf-8
|
2 |
+
# Copyright (c) 2025 inclusionAI.
|
3 |
+
|
4 |
+
plan_sys_prompt = """
|
5 |
+
You are an AI agent designed to automate tasks. Your goal is to accomplish the ultimate task following the rules.
|
6 |
+
|
7 |
+
# Input Format
|
8 |
+
Task
|
9 |
+
Previous steps
|
10 |
+
|
11 |
+
# Response Rules
|
12 |
+
1. RESPONSE FORMAT: You must ALWAYS respond with valid JSON or text.
|
13 |
+
|
14 |
+
2. ACTIONS: You can specify one actions in the list to be executed in sequence.
|
15 |
+
|
16 |
+
3. REQUIREMENTS:
|
17 |
+
- If you want to extract some information, you can use example_search_agent gets related info and url, then you can use browser_agent extract info from specific url.
|
18 |
+
- If you want to search, you need use example_search_agent and give the specific task.
|
19 |
+
- If you want to extract, you need use broswer_agent and give the task contains specific url. you can give two url once for browser agent, and tell browser agent only need extract from one url. if one url is invalid, use another url for replace.
|
20 |
+
- If you want to write, you need use example_write_agent and give the task and refer, the task needs be very detailed and contains all requirements.
|
21 |
+
|
22 |
+
4. Pipeline:
|
23 |
+
- If you have many information to search. you should choose search tool - extract loop many times.
|
24 |
+
|
25 |
+
5. TASK COMPLETION:
|
26 |
+
- Use the done action as the last action as soon as the ultimate task is complete
|
27 |
+
- Dont use "done" before you are done with everything the user asked you, except you reach the last step of max_steps.
|
28 |
+
- If you reach your last step, use the done action even if the task is not fully finished. Provide all the information you have gathered so far. If the ultimate task is completly finished set success to true. If not everything the user asked for is completed set success in done to false!
|
29 |
+
- If you have to do something repeatedly for example the task says for "each", or "for all", or "x times", count always inside "memory" how many times you have done it and how many remain. Don't stop until you have completed like the task asked you. Only call done after the last step.
|
30 |
+
- Don't hallucinate actions
|
31 |
+
- Make sure you include everything you found out for the ultimate task in the done text parameter. Do not just say you are done, but include the requested information of the task.
|
32 |
+
"""
|
33 |
+
# 6. Output Format:
|
34 |
+
# - You need first evaluate previous goal, and then save important things into memory, then give the next goal and use tool call to execute task.
|
35 |
+
# 'current_state': {
|
36 |
+
# 'evaluation_previous_goal': 'Success - I completed search and gets the url',
|
37 |
+
# 'memory': 'search compeleted and gets url',
|
38 |
+
# 'next_goal': 'extract information from the related url',
|
39 |
+
# },
|
40 |
+
#
|
41 |
+
# 7. You need execute task step by step, so that you can only give one simple action per time. do not search much more info one times. (you can search, extract, search, extract, ..., write)
|
42 |
+
# """
|
43 |
+
|
44 |
+
plan_prompt = """Your ultimate task is: {task}. If you achieved your ultimate task, stop everything and use the done action in the next step to complete the task. If not, continue as usual.
|
45 |
+
You should break down the retrieval task into small atomic granularities, search small and extract, and then search next. you should only take one action / function call once per time.
|
46 |
+
"""
|
47 |
+
|
48 |
+
search_sys_prompt = "You are a helpful search agent. please only use one action complete this task (only search once), at least results 6 pages."
|
49 |
+
|
50 |
+
search_prompt = """
|
51 |
+
Please act as a search agent, constructing appropriate keywords and search terms, using search toolkit to collect relevant information, including urls, webpage snapshots, etc.
|
52 |
+
|
53 |
+
Here are the question: {task}
|
54 |
+
"""
|
55 |
+
|
56 |
+
search_output_prompt = """
|
57 |
+
1. RESPONSE FORMAT: You must ALWAYS respond with valid JSON in this exact format:
|
58 |
+
{"action":[{{"one_action_name": {{// action-specific parameter}}}}, // ... more actions in sequence]}
|
59 |
+
"""
|
60 |
+
|
61 |
+
write_sys_prompt = "You are a helpful write agent."
|
62 |
+
|
63 |
+
write_prompt = """
|
64 |
+
Please act as a write agent, constructing appropriate keywords and search terms, using search toolkit to collect relevant information, including urls, webpage snapshots, etc.
|
65 |
+
|
66 |
+
Here are the write task: {task}
|
67 |
+
|
68 |
+
please only use one action complete this task.
|
69 |
+
"""
|
70 |
+
# Here is the reference information: {reference}
|
71 |
+
write_output_prompt = """
|
72 |
+
1. RESPONSE FORMAT: You must ALWAYS respond with valid JSON in this exact format:
|
73 |
+
{"action":[{{"one_action_name": {{// action-specific parameter}}}}, // ... more actions in sequence]}
|
74 |
+
"""
|
examples/travel/run.py
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding: utf-8
|
2 |
+
# Copyright (c) 2025 inclusionAI.
|
3 |
+
from aworld.config.conf import AgentConfig, ToolConfig
|
4 |
+
from aworld.agents.llm_agent import Agent
|
5 |
+
from aworld.config import ModelConfig
|
6 |
+
from aworld.core.agent.swarm import Swarm, TeamSwarm, GraphBuildType
|
7 |
+
from aworld.core.task import Task
|
8 |
+
from aworld.runner import Runners
|
9 |
+
from examples.browsers.agent import BrowserAgent
|
10 |
+
from examples.browsers.config import BrowserAgentConfig
|
11 |
+
from examples.tools.common import Tools
|
12 |
+
from examples.tools.conf import BrowserToolConfig
|
13 |
+
from examples.tools.tool_action import SearchAction
|
14 |
+
from examples.travel.prompts import *
|
15 |
+
|
16 |
+
model_config = ModelConfig(
|
17 |
+
llm_provider="openai",
|
18 |
+
llm_model_name="gpt-4o",
|
19 |
+
# need to set llm_api_key for use LLM
|
20 |
+
)
|
21 |
+
agent_config = AgentConfig(
|
22 |
+
llm_config=model_config,
|
23 |
+
use_vision=False
|
24 |
+
)
|
25 |
+
|
26 |
+
plan = Agent(
|
27 |
+
conf=agent_config,
|
28 |
+
name="example_plan_agent",
|
29 |
+
system_prompt=plan_sys_prompt,
|
30 |
+
agent_prompt=plan_prompt,
|
31 |
+
agent_names=['browser_agent'],
|
32 |
+
step_reset=False
|
33 |
+
)
|
34 |
+
|
35 |
+
search = Agent(
|
36 |
+
conf=agent_config,
|
37 |
+
name="example_search_agent",
|
38 |
+
desc="search ",
|
39 |
+
system_prompt=search_sys_prompt,
|
40 |
+
agent_prompt=search_prompt,
|
41 |
+
tool_names=[Tools.SEARCH_API.value],
|
42 |
+
black_tool_actions={Tools.SEARCH_API.value: [SearchAction.DUCK_GO.value.name, SearchAction.WIKI.value.name,
|
43 |
+
SearchAction.GOOGLE.value.name]}
|
44 |
+
)
|
45 |
+
|
46 |
+
write = Agent(
|
47 |
+
conf=agent_config,
|
48 |
+
name="example_write_agent",
|
49 |
+
system_prompt=write_sys_prompt,
|
50 |
+
agent_prompt=write_prompt,
|
51 |
+
tool_names=[Tools.HTML.value],
|
52 |
+
)
|
53 |
+
|
54 |
+
browser_agent = BrowserAgent(
|
55 |
+
name='browser_agent',
|
56 |
+
desc="browser_agent can execute extract web info task and open local file task, if you want to use browser agent to open local file, you should give the specific absolutely file path in params.",
|
57 |
+
conf=BrowserAgentConfig(
|
58 |
+
llm_config=model_config,
|
59 |
+
use_vision=False
|
60 |
+
),
|
61 |
+
tool_names=[Tools.BROWSER.value]
|
62 |
+
)
|
63 |
+
|
64 |
+
|
65 |
+
def main():
|
66 |
+
goal = """
|
67 |
+
I need a 7-day Japan itinerary from April 2 to April 8 2025, departing from Hangzhou, We want to see beautiful cherry blossoms and experience traditional Japanese culture (kendo, tea ceremonies, Zen meditation). We would like to taste matcha in Uji and enjoy the hot springs in Kobe. I am planning to propose during this trip, so I need a special location recommendation. Please provide a detailed itinerary and create a simple HTML travel handbook that includes a 7-day Japan itinerary, an updated cherry blossom table, attraction descriptions, essential Japanese phrases, and travel tips for us to reference throughout our journey.
|
68 |
+
you need search and extract different info 1 times, and then write, at last use browser agent goto the html url and then, complete the task.
|
69 |
+
"""
|
70 |
+
# swarm = Swarm((plan, search), (plan, browser_agent), (plan, write), build_type=GraphBuildType.TEAM)
|
71 |
+
swarm = TeamSwarm(plan, search, browser_agent, write)
|
72 |
+
task = Task(
|
73 |
+
swarm=swarm,
|
74 |
+
input=goal,
|
75 |
+
tools_conf={
|
76 |
+
Tools.BROWSER.value: BrowserToolConfig(width=800, height=720, use_async=True, llm_config=model_config),
|
77 |
+
Tools.HTML.value: ToolConfig(name="html", llm_config=model_config)
|
78 |
+
},
|
79 |
+
endless_threshold=5
|
80 |
+
)
|
81 |
+
|
82 |
+
Runners.sync_run_task(task)
|
83 |
+
|
84 |
+
|
85 |
+
if __name__ == '__main__':
|
86 |
+
main()
|