pycityagent 1.0.0__py3-none-any.whl → 2.0.0a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pycityagent/__init__.py +7 -3
- pycityagent/agent.py +180 -284
- pycityagent/economy/__init__.py +5 -0
- pycityagent/economy/econ_client.py +307 -0
- pycityagent/environment/__init__.py +7 -0
- pycityagent/environment/interact/interact.py +141 -0
- pycityagent/environment/sence/__init__.py +0 -0
- pycityagent/{brain → environment/sence}/static.py +1 -1
- pycityagent/environment/sidecar/__init__.py +8 -0
- pycityagent/environment/sidecar/sidecarv2.py +109 -0
- pycityagent/environment/sim/__init__.py +27 -0
- pycityagent/environment/sim/aoi_service.py +38 -0
- pycityagent/environment/sim/client.py +126 -0
- pycityagent/environment/sim/clock_service.py +43 -0
- pycityagent/environment/sim/economy_services.py +191 -0
- pycityagent/environment/sim/lane_service.py +110 -0
- pycityagent/environment/sim/light_service.py +120 -0
- pycityagent/environment/sim/person_service.py +294 -0
- pycityagent/environment/sim/road_service.py +38 -0
- pycityagent/environment/sim/social_service.py +58 -0
- pycityagent/environment/simulator.py +369 -0
- pycityagent/environment/utils/__init__.py +8 -0
- pycityagent/environment/utils/geojson.py +26 -0
- pycityagent/environment/utils/grpc.py +57 -0
- pycityagent/environment/utils/map_utils.py +157 -0
- pycityagent/environment/utils/protobuf.py +39 -0
- pycityagent/llm/__init__.py +6 -0
- pycityagent/llm/embedding.py +136 -0
- pycityagent/llm/llm.py +430 -0
- pycityagent/llm/llmconfig.py +15 -0
- pycityagent/llm/utils.py +6 -0
- pycityagent/memory/__init__.py +11 -0
- pycityagent/memory/const.py +41 -0
- pycityagent/memory/memory.py +453 -0
- pycityagent/memory/memory_base.py +168 -0
- pycityagent/memory/profile.py +165 -0
- pycityagent/memory/self_define.py +165 -0
- pycityagent/memory/state.py +173 -0
- pycityagent/memory/utils.py +27 -0
- pycityagent/message/__init__.py +0 -0
- pycityagent/simulation/__init__.py +7 -0
- pycityagent/simulation/interview.py +36 -0
- pycityagent/simulation/simulation.py +286 -0
- pycityagent/simulation/survey/__init__.py +9 -0
- pycityagent/simulation/survey/manager.py +67 -0
- pycityagent/simulation/survey/models.py +49 -0
- pycityagent/simulation/ui/__init__.py +3 -0
- pycityagent/simulation/ui/interface.py +602 -0
- pycityagent/utils/__init__.py +0 -0
- pycityagent/utils/decorators.py +89 -0
- pycityagent/utils/parsers/__init__.py +12 -0
- pycityagent/utils/parsers/code_block_parser.py +37 -0
- pycityagent/utils/parsers/json_parser.py +86 -0
- pycityagent/utils/parsers/parser_base.py +60 -0
- pycityagent/workflow/__init__.py +22 -0
- pycityagent/workflow/block.py +137 -0
- pycityagent/workflow/prompt.py +72 -0
- pycityagent/workflow/tool.py +246 -0
- pycityagent/workflow/trigger.py +66 -0
- pycityagent-2.0.0a1.dist-info/METADATA +208 -0
- pycityagent-2.0.0a1.dist-info/RECORD +65 -0
- {pycityagent-1.0.0.dist-info → pycityagent-2.0.0a1.dist-info}/WHEEL +1 -2
- pycityagent/ac/__init__.py +0 -6
- pycityagent/ac/ac.py +0 -50
- pycityagent/ac/action.py +0 -14
- pycityagent/ac/controled.py +0 -13
- pycityagent/ac/converse.py +0 -31
- pycityagent/ac/idle.py +0 -17
- pycityagent/ac/shop.py +0 -80
- pycityagent/ac/trip.py +0 -37
- pycityagent/brain/__init__.py +0 -10
- pycityagent/brain/brain.py +0 -52
- pycityagent/brain/brainfc.py +0 -10
- pycityagent/brain/memory.py +0 -541
- pycityagent/brain/persistence/social.py +0 -1
- pycityagent/brain/persistence/spatial.py +0 -14
- pycityagent/brain/reason/shop.py +0 -37
- pycityagent/brain/reason/social.py +0 -148
- pycityagent/brain/reason/trip.py +0 -67
- pycityagent/brain/reason/user.py +0 -122
- pycityagent/brain/retrive/social.py +0 -6
- pycityagent/brain/scheduler.py +0 -408
- pycityagent/brain/sence.py +0 -375
- pycityagent/cc/__init__.py +0 -5
- pycityagent/cc/cc.py +0 -102
- pycityagent/cc/conve.py +0 -6
- pycityagent/cc/idle.py +0 -20
- pycityagent/cc/shop.py +0 -6
- pycityagent/cc/trip.py +0 -13
- pycityagent/cc/user.py +0 -13
- pycityagent/hubconnector/__init__.py +0 -3
- pycityagent/hubconnector/hubconnector.py +0 -137
- pycityagent/image/__init__.py +0 -3
- pycityagent/image/image.py +0 -158
- pycityagent/simulator.py +0 -161
- pycityagent/st/__init__.py +0 -4
- pycityagent/st/st.py +0 -96
- pycityagent/urbanllm/__init__.py +0 -3
- pycityagent/urbanllm/urbanllm.py +0 -132
- pycityagent-1.0.0.dist-info/LICENSE +0 -21
- pycityagent-1.0.0.dist-info/METADATA +0 -181
- pycityagent-1.0.0.dist-info/RECORD +0 -48
- pycityagent-1.0.0.dist-info/top_level.txt +0 -1
- /pycityagent/{brain/persistence/__init__.py → config.py} +0 -0
- /pycityagent/{brain/reason → environment/interact}/__init__.py +0 -0
- /pycityagent/{brain/retrive → environment/message}/__init__.py +0 -0
@@ -1,148 +0,0 @@
|
|
1
|
-
import json
|
2
|
-
|
3
|
-
async def handleConve(wk, retrives):
|
4
|
-
"""
|
5
|
-
对话处理
|
6
|
-
Conversation handler
|
7
|
-
|
8
|
-
Args:
|
9
|
-
- wk (WorkingMemory)
|
10
|
-
- retrives (dict): the MemoryRetrive output collection
|
11
|
-
|
12
|
-
Returns:
|
13
|
-
- (Tuple([list[int], list[str]])): (id, message)
|
14
|
-
"""
|
15
|
-
soul = wk._agent.Soul
|
16
|
-
familiers = retrives['familiers']
|
17
|
-
ids = []
|
18
|
-
messages = []
|
19
|
-
if wk.enable_social:
|
20
|
-
# * 接受其他agent发送过来的消息
|
21
|
-
if wk.msg_agent_unhandle:
|
22
|
-
for from_id, content_dialog in wk.msg_agent_unhandle.items():
|
23
|
-
if from_id in wk.agent_converse_buffer.keys():
|
24
|
-
# * 正在进行对话
|
25
|
-
if content_dialog[0]['content'] == 'End':
|
26
|
-
# * 接受到End, 说明对方认为对话已结束
|
27
|
-
if from_id in wk.msg_agent_still.keys():
|
28
|
-
del wk.msg_agent_still[from_id]
|
29
|
-
else:
|
30
|
-
# * 正常进行对话
|
31
|
-
wk.agent_converse_buffer[from_id] += content_dialog
|
32
|
-
dialog = wk.agent_converse_buffer[from_id]
|
33
|
-
print(dialog)
|
34
|
-
resp = soul.text_request(dialog)
|
35
|
-
if resp == 'Finished':
|
36
|
-
del wk.msg_agent_still[from_id]
|
37
|
-
ids.append(from_id)
|
38
|
-
messages.append('End')
|
39
|
-
else:
|
40
|
-
wk.agent_converse_buffer[from_id].append({
|
41
|
-
'role': 'assistant',
|
42
|
-
'content': resp
|
43
|
-
})
|
44
|
-
ids.append(from_id)
|
45
|
-
messages.append(resp)
|
46
|
-
print(f'回复: {resp}')
|
47
|
-
wk.msg_agent_still[from_id] = 20
|
48
|
-
else:
|
49
|
-
# * 之前没有进行过对话 - 他人主动问好
|
50
|
-
# * 判断是否进行对话 - 目前只支持熟人对话
|
51
|
-
if from_id in familiers.keys():
|
52
|
-
wk.agent_converse_buffer[from_id].append({
|
53
|
-
'role': 'system',
|
54
|
-
'content': f'''和你对话的人是: {familiers[from_id]['name']}, 和你的关系是{familiers[from_id]['relation']} {familiers[from_id]['learned']}'''
|
55
|
-
})
|
56
|
-
wk.agent_converse_buffer[from_id] += content_dialog
|
57
|
-
dialog = wk.agent_converse_buffer[from_id]
|
58
|
-
resp = soul.text_request(dialog)
|
59
|
-
if resp == 'Finished':
|
60
|
-
# * 不理睬
|
61
|
-
ids.append(from_id)
|
62
|
-
messages.append('End')
|
63
|
-
else:
|
64
|
-
# * 回复
|
65
|
-
wk.agent_converse_buffer[from_id].append({
|
66
|
-
'role': 'assistant',
|
67
|
-
'content': resp
|
68
|
-
})
|
69
|
-
ids.append(from_id)
|
70
|
-
messages.append(resp)
|
71
|
-
wk.msg_agent_still[from_id] = 20
|
72
|
-
wk.msg_agent_unhandle.clear() # 清空
|
73
|
-
else:
|
74
|
-
# * 主动问好
|
75
|
-
# * 判断周围是否有熟人
|
76
|
-
familier_around = []
|
77
|
-
for person in wk.sence['persons']:
|
78
|
-
if person['id'] in familiers.keys():
|
79
|
-
familier_around.append((person, familiers[person['id']]))
|
80
|
-
if len(familier_around) > 0:
|
81
|
-
# 周围有熟人
|
82
|
-
# * 感兴趣人物筛选
|
83
|
-
dialog = wk.most_interest_dialog+[{'role': 'user', 'content': f'''我的基本信息为: {wk._agent.Image.get_profile()}'''}]
|
84
|
-
familier_text = ''''''
|
85
|
-
for person in familier_around:
|
86
|
-
familier_text += f'''[人物id: {person[0]['id']}, 姓名: {person[1]['name']}, 和我的关系: {person[1]['relation']}, 其他信息: {person[1]['learned']}]\n'''
|
87
|
-
dialog += [{'role': 'user', 'content': f'''周围人物信息: \n{familier_text}'''}]
|
88
|
-
resp = soul.text_request(dialog)
|
89
|
-
try:
|
90
|
-
resp_dict = json.loads(resp)
|
91
|
-
interested_id = familiers[resp_dict['id']]
|
92
|
-
conve = resp_dict['conve']
|
93
|
-
# * 是否发起对话
|
94
|
-
if conve == '是':
|
95
|
-
# 发起对话
|
96
|
-
wk.agent_converse_buffer[interested_id].append({
|
97
|
-
'role': 'system',
|
98
|
-
'content': f'''和你对话的人是: {familiers[interested_id]['name']}, 和你的关系是{familiers[interested_id]['relation']} {familiers[interested_id]['learned']}'''
|
99
|
-
})
|
100
|
-
hello_dialog = wk.agent_converse_buffer[interested_id] + [{'role': 'user', 'content': f'''假设你主动向对方问好, 你会说什么?'''}]
|
101
|
-
hello = soul.text_request(hello_dialog)
|
102
|
-
wk.agent_converse_buffer[interested_id].append({'role': 'system', 'content': f'你主动问好说: {hello}'})
|
103
|
-
ids.append(interested_id)
|
104
|
-
messages.append(hello)
|
105
|
-
wk.msg_agent_still[interested_id] = 20
|
106
|
-
except:
|
107
|
-
print("社交信息理解失败")
|
108
|
-
|
109
|
-
# * 处理对话对象挂断或突然终止对话的情况
|
110
|
-
to_del = []
|
111
|
-
for id in wk.msg_agent_still.keys():
|
112
|
-
wk.msg_agent_still[id] -= 1
|
113
|
-
if wk.msg_agent_still[id] <= 0:
|
114
|
-
to_del.append(id)
|
115
|
-
for id in to_del:
|
116
|
-
del wk.msg_agent_still[id]
|
117
|
-
|
118
|
-
return (ids, messages)
|
119
|
-
|
120
|
-
async def startConve(wk):
|
121
|
-
"""
|
122
|
-
判断是否进入/保持对话状态
|
123
|
-
Whether enter or stay in 'conve' state
|
124
|
-
|
125
|
-
Args:
|
126
|
-
- wk (WorkingMemory)
|
127
|
-
|
128
|
-
Returns:
|
129
|
-
- (bool): if True, enter 'conve' state, else not
|
130
|
-
"""
|
131
|
-
if len(wk.msg_agent_still) > 0:
|
132
|
-
return True
|
133
|
-
return False
|
134
|
-
|
135
|
-
async def endConve(wk):
|
136
|
-
"""
|
137
|
-
判断是否结束对话(所有对话)
|
138
|
-
Whther end conversations (all conversations)
|
139
|
-
|
140
|
-
Args:
|
141
|
-
- wk (WorkingMemory)
|
142
|
-
|
143
|
-
Returns:
|
144
|
-
- (bool): if True, all conversations are ended, else not
|
145
|
-
"""
|
146
|
-
if len(wk.msg_agent_still) > 0:
|
147
|
-
return False
|
148
|
-
return True
|
pycityagent/brain/reason/trip.py
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
from ..scheduler import *
|
2
|
-
import time
|
3
|
-
|
4
|
-
async def startTrip(wk):
|
5
|
-
"""
|
6
|
-
判断是否开始行程
|
7
|
-
Whether start trip
|
8
|
-
|
9
|
-
Args:
|
10
|
-
- wk (WorkingMemory)
|
11
|
-
|
12
|
-
Returns:
|
13
|
-
- (bool): if True, start target trip, else not
|
14
|
-
"""
|
15
|
-
now = wk.scheduler.now
|
16
|
-
if now == None:
|
17
|
-
return False
|
18
|
-
elif now.type.value != ScheduleType.TRIP.value:
|
19
|
-
return False
|
20
|
-
elif now.is_set:
|
21
|
-
return False
|
22
|
-
else:
|
23
|
-
time_now = wk.sence['time']
|
24
|
-
if now.time <= time_now:
|
25
|
-
return True
|
26
|
-
else:
|
27
|
-
return False
|
28
|
-
|
29
|
-
async def tripArrived(wk):
|
30
|
-
"""
|
31
|
-
判断是否已到达目的地
|
32
|
-
Whether arrived target location
|
33
|
-
|
34
|
-
Args:
|
35
|
-
- wk (WorkingMemory)
|
36
|
-
|
37
|
-
Returns:
|
38
|
-
- (bool): if True, has arrived, else not
|
39
|
-
"""
|
40
|
-
now = wk.scheduler.now
|
41
|
-
if now == None:
|
42
|
-
return False
|
43
|
-
elif now.type.value != ScheduleType.TRIP.value:
|
44
|
-
return False
|
45
|
-
else:
|
46
|
-
if now.arrived:
|
47
|
-
return True
|
48
|
-
return False
|
49
|
-
|
50
|
-
async def routeFailed(wk):
|
51
|
-
"""
|
52
|
-
判断导航是否失败
|
53
|
-
Whether the route request failed
|
54
|
-
|
55
|
-
Args:
|
56
|
-
- wk (WorkingMemory)
|
57
|
-
|
58
|
-
Returns:
|
59
|
-
- (bool): if True, failed, else not
|
60
|
-
"""
|
61
|
-
now = wk.scheduler.now
|
62
|
-
if now == None or now.type.value != ScheduleType.TRIP.value:
|
63
|
-
return False
|
64
|
-
elif now.route_failed:
|
65
|
-
wk._agent.Hub.Update([AgentMessage(wk._agent.Hub._agent_id, int(time.time()*1000), '抱歉, 当前行程导航请求失败, 已跳过该行程', None, None)])
|
66
|
-
return True
|
67
|
-
return False
|
pycityagent/brain/reason/user.py
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
from pycitysim.apphub import AgentMessage
|
2
|
-
import time
|
3
|
-
import json
|
4
|
-
import copy
|
5
|
-
|
6
|
-
async def hasUserControl(wk) -> bool:
|
7
|
-
"""
|
8
|
-
判断是否有用户指令
|
9
|
-
Whether there have user commond
|
10
|
-
|
11
|
-
Args:
|
12
|
-
- wk (WorkingMemory)
|
13
|
-
|
14
|
-
Returns:
|
15
|
-
- (bool): if True, have user commond, else not
|
16
|
-
"""
|
17
|
-
soul = wk._agent.Soul
|
18
|
-
hub = wk._agent.Hub
|
19
|
-
if len(wk.msg_user_unhandle) > 0:
|
20
|
-
# * 理解用户对话目的
|
21
|
-
understand_dialog = copy.deepcopy(wk.understanding_prompt)
|
22
|
-
user_dialog = []
|
23
|
-
contin_flag = True
|
24
|
-
for user_message in wk.msg_user_unhandle:
|
25
|
-
content = user_message.content
|
26
|
-
sub = [{'role': 'user', 'content': content}]
|
27
|
-
user_dialog += sub
|
28
|
-
print(f'[用户消息]: {content}')
|
29
|
-
if '开' in content or '启' in content or 'enable' in content :
|
30
|
-
if '用户交互' in content or 'interaction' in content:
|
31
|
-
wk._agent.enable_user_interaction()
|
32
|
-
hub.Update([AgentMessage(hub._agent_id, int(time.time()*1000), '已启动用户交互功能', None, None)])
|
33
|
-
contin_flag = False
|
34
|
-
elif wk.enable_user_interaction and ('街景' in content or 'streetview' in content):
|
35
|
-
wk._agent.enable_streetview()
|
36
|
-
hub.Update([AgentMessage(hub._agent_id, int(time.time()*1000), '已启动街景功能(周围存在街景信息时自动呈现于屏幕右下角)', None, None)])
|
37
|
-
contin_flag = False
|
38
|
-
elif wk.enable_user_interaction and ('经济' in content or 'economy' in content):
|
39
|
-
wk._agent.enable_economy_behavior()
|
40
|
-
hub.Update([AgentMessage(hub._agent_id, int(time.time()*1000), '已启动经济行为模拟', None, None)])
|
41
|
-
contin_flag = False
|
42
|
-
elif wk.enable_user_interaction and ('社交' in content or 'social' in content):
|
43
|
-
wk._agent.enable_social_behavior()
|
44
|
-
hub.Update([AgentMessage(hub._agent_id, int(time.time()*1000), '已启动社交行为模拟', None, None)])
|
45
|
-
contin_flag = False
|
46
|
-
elif '关' in content or 'diable' in content or '闭' in content:
|
47
|
-
if '用户交互' in content or 'interaction' in content:
|
48
|
-
wk._agent.disable_user_interaction()
|
49
|
-
hub.Update([AgentMessage(hub._agent_id, int(time.time()*1000), '已关闭用户交互功能', None, None)])
|
50
|
-
contin_flag = False
|
51
|
-
elif wk.enable_user_interaction and ('街景' in content or 'streetview' in content):
|
52
|
-
wk._agent.disable_streetview()
|
53
|
-
hub.Update([AgentMessage(hub._agent_id, int(time.time()*1000), '已关闭街景功能', None, None)])
|
54
|
-
contin_flag = False
|
55
|
-
elif wk.enable_user_interaction and ('经济' in content or 'economy' in content):
|
56
|
-
wk._agent.disable_economy_behavior()
|
57
|
-
hub.Update([AgentMessage(hub._agent_id, int(time.time()*1000), '已关闭经济行为模拟', None, None)])
|
58
|
-
contin_flag = False
|
59
|
-
elif wk.enable_user_interaction and ('社交' in content or 'social' in content):
|
60
|
-
wk._agent.disable_social_behavior()
|
61
|
-
hub.Update([AgentMessage(hub._agent_id, int(time.time()*1000), '已关闭社交行为模拟', None, None)])
|
62
|
-
contin_flag = False
|
63
|
-
|
64
|
-
if not contin_flag:
|
65
|
-
return False
|
66
|
-
if not wk.enable_user_interaction:
|
67
|
-
# * 关闭了交互功能
|
68
|
-
hub.Update([AgentMessage(hub._agent_id, int(time.time()*1000), '抱歉, 我无法处理您的信息, 可能是因为您关闭了用户交互通道或该Agent不支持用户交互', None, None)])
|
69
|
-
return False
|
70
|
-
understand_dialog += user_dialog
|
71
|
-
understand = soul.text_request(understand_dialog)
|
72
|
-
|
73
|
-
if understand == '对话':
|
74
|
-
wk.set_user_converse_background()
|
75
|
-
dialog = copy.deepcopy(wk.user_converse_buffer)
|
76
|
-
if wk.current_target != None:
|
77
|
-
dialog.insert(3, {'role': 'system', 'content': f'你目前的计划: {wk.current_target}'})
|
78
|
-
dialog += user_dialog
|
79
|
-
print(dialog)
|
80
|
-
resp = soul.text_request(dialog)
|
81
|
-
if "Error" in resp:
|
82
|
-
hub.Update([AgentMessage(hub._agent_id, int(time.time()*1000), "抱歉, 我暂时无法理解您的意思", None, None)])
|
83
|
-
else:
|
84
|
-
wk.user_converse_buffer += user_dialog
|
85
|
-
wk.user_converse_buffer += [{'role': 'assistant', 'content': resp}]
|
86
|
-
print(wk.user_converse_buffer) # 添加到记忆中
|
87
|
-
hub.Update([AgentMessage(hub._agent_id, int(time.time()*1000), resp, None, None)])
|
88
|
-
wk.msg_user_unhandle = []
|
89
|
-
return False
|
90
|
-
elif understand == '控制':
|
91
|
-
commond_to_target_dialog = [
|
92
|
-
{'role': 'system', 'content': '你是一名语义理解大师, 你需要理解用户输入的目的, 并从第一视角[我]出发返回理解结果'},
|
93
|
-
{'role': 'system', 'content': '例如用户输入: 你现在去买菜, 你将输出: 我现在要去买菜'},
|
94
|
-
{'role': 'system', 'content': '例如用户输入: 你现在去公司工作, 你将输出: 我现在准备去公司工作'}
|
95
|
-
]
|
96
|
-
for user_message in wk.msg_user_unhandle:
|
97
|
-
content = user_message.content
|
98
|
-
commond_to_target_dialog += [{'role': 'user', 'content': content}]
|
99
|
-
wk.current_target = soul.text_request(commond_to_target_dialog)
|
100
|
-
wk.has_user_command = True
|
101
|
-
wk.msg_user_unhandle = []
|
102
|
-
return True
|
103
|
-
else:
|
104
|
-
# * 无法理解
|
105
|
-
hub.Update([AgentMessage(hub._agent_id, int(time.time()*1000), '抱歉,我无法理解您的话,您可以尝试换一种表达方式以帮助我理解', None, None)])
|
106
|
-
wk.msg_user_unhandle = []
|
107
|
-
return False
|
108
|
-
|
109
|
-
async def endUserControl(wk) -> bool:
|
110
|
-
"""
|
111
|
-
判断用户控制是否已结束
|
112
|
-
Whether user control has ended
|
113
|
-
|
114
|
-
Args:
|
115
|
-
- wk (WorkingMemory)
|
116
|
-
|
117
|
-
Returns:
|
118
|
-
- (bool): if True, ended, else not
|
119
|
-
"""
|
120
|
-
if wk.has_user_command == False:
|
121
|
-
return True
|
122
|
-
return False
|