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.
Files changed (106) hide show
  1. pycityagent/__init__.py +7 -3
  2. pycityagent/agent.py +180 -284
  3. pycityagent/economy/__init__.py +5 -0
  4. pycityagent/economy/econ_client.py +307 -0
  5. pycityagent/environment/__init__.py +7 -0
  6. pycityagent/environment/interact/interact.py +141 -0
  7. pycityagent/environment/sence/__init__.py +0 -0
  8. pycityagent/{brain → environment/sence}/static.py +1 -1
  9. pycityagent/environment/sidecar/__init__.py +8 -0
  10. pycityagent/environment/sidecar/sidecarv2.py +109 -0
  11. pycityagent/environment/sim/__init__.py +27 -0
  12. pycityagent/environment/sim/aoi_service.py +38 -0
  13. pycityagent/environment/sim/client.py +126 -0
  14. pycityagent/environment/sim/clock_service.py +43 -0
  15. pycityagent/environment/sim/economy_services.py +191 -0
  16. pycityagent/environment/sim/lane_service.py +110 -0
  17. pycityagent/environment/sim/light_service.py +120 -0
  18. pycityagent/environment/sim/person_service.py +294 -0
  19. pycityagent/environment/sim/road_service.py +38 -0
  20. pycityagent/environment/sim/social_service.py +58 -0
  21. pycityagent/environment/simulator.py +369 -0
  22. pycityagent/environment/utils/__init__.py +8 -0
  23. pycityagent/environment/utils/geojson.py +26 -0
  24. pycityagent/environment/utils/grpc.py +57 -0
  25. pycityagent/environment/utils/map_utils.py +157 -0
  26. pycityagent/environment/utils/protobuf.py +39 -0
  27. pycityagent/llm/__init__.py +6 -0
  28. pycityagent/llm/embedding.py +136 -0
  29. pycityagent/llm/llm.py +430 -0
  30. pycityagent/llm/llmconfig.py +15 -0
  31. pycityagent/llm/utils.py +6 -0
  32. pycityagent/memory/__init__.py +11 -0
  33. pycityagent/memory/const.py +41 -0
  34. pycityagent/memory/memory.py +453 -0
  35. pycityagent/memory/memory_base.py +168 -0
  36. pycityagent/memory/profile.py +165 -0
  37. pycityagent/memory/self_define.py +165 -0
  38. pycityagent/memory/state.py +173 -0
  39. pycityagent/memory/utils.py +27 -0
  40. pycityagent/message/__init__.py +0 -0
  41. pycityagent/simulation/__init__.py +7 -0
  42. pycityagent/simulation/interview.py +36 -0
  43. pycityagent/simulation/simulation.py +286 -0
  44. pycityagent/simulation/survey/__init__.py +9 -0
  45. pycityagent/simulation/survey/manager.py +67 -0
  46. pycityagent/simulation/survey/models.py +49 -0
  47. pycityagent/simulation/ui/__init__.py +3 -0
  48. pycityagent/simulation/ui/interface.py +602 -0
  49. pycityagent/utils/__init__.py +0 -0
  50. pycityagent/utils/decorators.py +89 -0
  51. pycityagent/utils/parsers/__init__.py +12 -0
  52. pycityagent/utils/parsers/code_block_parser.py +37 -0
  53. pycityagent/utils/parsers/json_parser.py +86 -0
  54. pycityagent/utils/parsers/parser_base.py +60 -0
  55. pycityagent/workflow/__init__.py +22 -0
  56. pycityagent/workflow/block.py +137 -0
  57. pycityagent/workflow/prompt.py +72 -0
  58. pycityagent/workflow/tool.py +246 -0
  59. pycityagent/workflow/trigger.py +66 -0
  60. pycityagent-2.0.0a1.dist-info/METADATA +208 -0
  61. pycityagent-2.0.0a1.dist-info/RECORD +65 -0
  62. {pycityagent-1.0.0.dist-info → pycityagent-2.0.0a1.dist-info}/WHEEL +1 -2
  63. pycityagent/ac/__init__.py +0 -6
  64. pycityagent/ac/ac.py +0 -50
  65. pycityagent/ac/action.py +0 -14
  66. pycityagent/ac/controled.py +0 -13
  67. pycityagent/ac/converse.py +0 -31
  68. pycityagent/ac/idle.py +0 -17
  69. pycityagent/ac/shop.py +0 -80
  70. pycityagent/ac/trip.py +0 -37
  71. pycityagent/brain/__init__.py +0 -10
  72. pycityagent/brain/brain.py +0 -52
  73. pycityagent/brain/brainfc.py +0 -10
  74. pycityagent/brain/memory.py +0 -541
  75. pycityagent/brain/persistence/social.py +0 -1
  76. pycityagent/brain/persistence/spatial.py +0 -14
  77. pycityagent/brain/reason/shop.py +0 -37
  78. pycityagent/brain/reason/social.py +0 -148
  79. pycityagent/brain/reason/trip.py +0 -67
  80. pycityagent/brain/reason/user.py +0 -122
  81. pycityagent/brain/retrive/social.py +0 -6
  82. pycityagent/brain/scheduler.py +0 -408
  83. pycityagent/brain/sence.py +0 -375
  84. pycityagent/cc/__init__.py +0 -5
  85. pycityagent/cc/cc.py +0 -102
  86. pycityagent/cc/conve.py +0 -6
  87. pycityagent/cc/idle.py +0 -20
  88. pycityagent/cc/shop.py +0 -6
  89. pycityagent/cc/trip.py +0 -13
  90. pycityagent/cc/user.py +0 -13
  91. pycityagent/hubconnector/__init__.py +0 -3
  92. pycityagent/hubconnector/hubconnector.py +0 -137
  93. pycityagent/image/__init__.py +0 -3
  94. pycityagent/image/image.py +0 -158
  95. pycityagent/simulator.py +0 -161
  96. pycityagent/st/__init__.py +0 -4
  97. pycityagent/st/st.py +0 -96
  98. pycityagent/urbanllm/__init__.py +0 -3
  99. pycityagent/urbanllm/urbanllm.py +0 -132
  100. pycityagent-1.0.0.dist-info/LICENSE +0 -21
  101. pycityagent-1.0.0.dist-info/METADATA +0 -181
  102. pycityagent-1.0.0.dist-info/RECORD +0 -48
  103. pycityagent-1.0.0.dist-info/top_level.txt +0 -1
  104. /pycityagent/{brain/persistence/__init__.py → config.py} +0 -0
  105. /pycityagent/{brain/reason → environment/interact}/__init__.py +0 -0
  106. /pycityagent/{brain/retrive → environment/message}/__init__.py +0 -0
@@ -1,10 +0,0 @@
1
- class BrainFunction:
2
- """
3
- 大脑功能模块模板类
4
- The template class of brain function
5
- """
6
- def __init__(self, agent) -> None:
7
- self._agent = agent
8
-
9
- def state_influence(self):
10
- '''agent state影响接口函数'''
@@ -1,541 +0,0 @@
1
- from typing import Any, Optional
2
- from abc import ABC, abstractmethod
3
- from enum import Enum
4
- import json
5
- from collections import defaultdict
6
- from .brainfc import BrainFunction
7
- from .scheduler import Scheduler
8
- from .persistence.spatial import spacialPersistence
9
- from .retrive.social import *
10
- from .reason.shop import *
11
- from .reason.trip import *
12
- from .reason.user import *
13
- from .reason.social import *
14
-
15
- BASE_CONVERSE_DIALOG = [
16
- {'role': 'system', 'content': '你是一个对话机器人,你将基于背景信息进行角色扮演并做出拟人的, 符合角色逻辑的回答(你的回答应该尽量口语化且与角色的性格特征相符)'},
17
- {'role': 'system', 'content': '你的回复内容应该被严格限制在角色信息之内, 如果你认为角色无法做出有效回复, 可以从该角色的视角出发表达自己的不足, 例如: 抱歉, 我暂时不知道你所说的内容'},
18
- {'role': 'system', 'content': '注意: 每次回复前, 你应该根据你们的对话内容进行判断该段对话是否可以结束或无回复必要(例如对方已经说了再见), 如是请输出Finished, 否则请正常回复'}
19
- ]
20
- """
21
- Agent对话前置system role dialog
22
- The basic system role dialog used for converse
23
- """
24
-
25
- class MemoryType:
26
- """
27
- Enum类: 判断记忆类型
28
- Enum class: memory type
29
-
30
- LongTermMemory (LTM): 长时记忆的存储
31
- Working Memory (WM): 当前工作记忆的存储
32
- """
33
- LTM = 1
34
- WM = 2
35
-
36
- class MemoryRetrive:
37
- """
38
- 用于从LTM中获取对应信息
39
- LTM retrive: get information from LTM
40
-
41
- Args:
42
- - source (str): the name of source LTM
43
- - out (str): the output name of retrived information
44
- - user_func (function): the defined function used for retriving
45
- """
46
- def __init__(self, source:str, out:str, user_func) -> None:
47
- self.source = source
48
- self.out = out
49
- self.user_func = user_func
50
-
51
- class MemoryReason:
52
- """
53
- 基于WM的记忆推理与生成, 可以添加MemoryRetrive模块以获取关联信息
54
- Memory Reason: reason new information from WK, your can add a list of MemoryRetrive to get related information
55
-
56
- Args:
57
- - out (str): the output name of memory reason
58
- - user_func (function): the defined function used for reasoning
59
- - retrivees (Optional[list[MemoryRetrive]]): a list of MemoryRetrive block that help to get related information from LTM
60
- """
61
- def __init__(self, out:str, user_func, retrives:Optional[list[MemoryRetrive]]=None) -> None:
62
- self.out = out
63
- self.user_func = user_func
64
- self.retrives = retrives
65
-
66
- class MemoryPersistence:
67
- """
68
- 记忆持久化: 将WM中的内容存储到LTM中
69
- Memory Persistence: store memory from WM to LTM
70
-
71
- Args:
72
- - target (str): the name of target LTM
73
- - user_func (function): the defined function used for persistence
74
- """
75
- def __init__(self, target: str, user_func) -> None:
76
- self.target = target # 指代的是目标记忆体
77
- self.user_func = user_func # 用户注入的可执行函数
78
-
79
- class MemoryController:
80
- """
81
- 记忆管理器
82
- Memory Controller
83
- """
84
- def __init__(self, agent, memory_config:dict=None) -> None:
85
- self._agent = agent
86
- self._soul = agent._soul
87
- if memory_config != None:
88
- pass
89
- else:
90
- self._wm = WorkingMemory(agent)
91
- self._spatial = SpatialMemory(agent)
92
- self._social = SocialMemory(agent)
93
-
94
- async def Forward(self):
95
- """
96
- 记忆模块主工作流
97
- Main working flow of Memory
98
- """
99
- await self._wm.senceReceive(self._agent.Brain.Sence.sence_buffer)
100
- await self._wm.Forward()
101
-
102
- def reset_Memory(self):
103
- """
104
- 重置记忆内容
105
- Reset Memory
106
- Notice: by now, this function only reset all social related information, including unhandled messages and working messages
107
- """
108
- self._social.unhandle = []
109
- self._social.still = []
110
-
111
- @property
112
- def Spatial(self):
113
- """
114
- 空间记忆 (LTM)
115
- Spatial Memory (LTM)
116
- """
117
- return self._spatial
118
-
119
- @property
120
- def Social(self):
121
- """
122
- 社交记忆 (LTM)
123
- Social Memory (LTM)
124
- """
125
- return self._social
126
-
127
- @property
128
- def Working(self):
129
- """
130
- 工作记忆 (WM)
131
- Working Memory (WM)
132
- """
133
- return self._wm
134
-
135
- @property
136
- def Soul(self):
137
- return self._soul
138
-
139
- @property
140
- def Hub(self):
141
- return self._agent._hub
142
-
143
- class Memory(BrainFunction):
144
- """
145
- 记忆模板类
146
- The template class of Memory: defined as a BrainFunction
147
- """
148
- def __init__(self, agent, type:MemoryType) -> None:
149
- super().__init__(agent)
150
- self.type = type
151
-
152
- def Forward(self, x):
153
- """
154
- 数据工作流
155
- The data workflow
156
- """
157
-
158
- def MemorySave(self):
159
- """
160
- 记忆存储
161
- Save Memory
162
- """
163
-
164
- def MemoryLoad(self, x):
165
- """
166
- 记忆恢复
167
- Load Memory
168
- """
169
-
170
- class WorkingMemory(Memory):
171
- """
172
- 当前工作记忆
173
- Working Memory
174
- """
175
- def __init__(self, agent) -> None:
176
- super().__init__(agent, MemoryType.WM)
177
- self.sence = None
178
- """
179
- 用于存储感知内容
180
- Store the sence content
181
- """
182
- self.scheduler = Scheduler(agent)
183
- """
184
- 关联的规划器
185
- The related Scheduler
186
- """
187
- self.Reason = {}
188
- """
189
- 用于存储Reason结果的buffer: key值为MemoryReason.out
190
- """
191
-
192
- # * agent social
193
- self.agent_converse_buffer = defaultdict(lambda: BASE_CONVERSE_DIALOG+[
194
- {'role': 'system', 'content': f'''[角色基本信息]: {self._agent.Image.get_profile()}'''},
195
- {'role': 'system', 'content': f'''[角色的空间知识]: {self._agent.Brain.Memory.Spatial.to_dialog_str()}'''},
196
- {'role': 'system', 'content': f'''[角色的社交关系]: {self._agent.Brain.Memory.Social.to_dialog_str()}'''}
197
- ])
198
- """
199
- 存储当前仍未结束的对话内容
200
- Store the content of working conversation
201
- """
202
-
203
- self.hello_dialog = [
204
- {'role': 'system', 'content': '你将基于用户提供的基本信息以及周围人物信息, 预测用户当前对哪个人最感兴趣, 是否会和该人物进行对话, 以及进行对话的理由'},
205
- {'role': 'system', 'content': '其中基本信息包含用户的个人信息, 周围人物信息包含他人的基本信息以及用户对该人物的了解'},
206
- {'role': 'system', 'content': '你只需要提供一个整数(该整数为对应人物的id)即可(请勿包含其他冗余信息)'},
207
- {'role': 'system', 'content': '''你的回答需要严格按照以下格式给出(请勿包含其他冗余信息):
208
- {"id": 感兴趣人物的id, "conve": 是否进行对话, 可选集合为[是, 否], 'explaination': 进行或不进行对话的理由}'''}
209
- ]
210
- """
211
- Agent主动打招呼的system role dialog
212
- The basic system role dialog used for saying hello
213
- """
214
-
215
- self.msg_agent_unhandle = {} # dict of unhandle agent messages
216
- """
217
- 存储未处理消息
218
- Store unhandled agent messages
219
- """
220
-
221
- self.msg_agent_still = {} # still on converse person_id
222
- """
223
- 存储正在进行对话的person_id
224
- Store the target person_id of conversations that still working
225
- """
226
-
227
- # * user message related
228
- self.current_target = None
229
- """
230
- 当前的目标
231
- Agent's current target
232
- """
233
- self.has_user_command = False
234
- """
235
- 是否有用户指令
236
- Whether there have user commond
237
- """
238
- self.user_converse_buffer = BASE_CONVERSE_DIALOG+[{'role': 'system', 'content': self._agent.Image.get_profile()}]
239
- """
240
- 存储用户对话信息
241
- Store user conversation content
242
- """
243
- self.understanding_prompt = [
244
- {'role': 'system', 'content': '请你根据用户的输入内容,判断用户向你发起对话的用意并返回结果,返回的结果只能是[对话]或[控制]中的一个'},
245
- {'role': 'system', 'content': '其中[对话]表示用户只是想与你进行常规对话;[控制]表示用户想要控制你的行动'},
246
- {'role': 'system', 'content': '例如用户输入: 你好, 你的返回结果为: 对话'},
247
- {'role': 'system', 'content': '例如用户输入: 你现在立刻去附近买菜, 你的返回结果为: 控制'}
248
- ]
249
- """
250
- 用于判断user对话意图的基础system role dialog
251
- The basic system role dialog used for interpreting converse intent, converse or commond
252
- """
253
-
254
- self.msg_user_unhandle = [] # unhandle user messages
255
- """
256
- 存储未处理的用户消息
257
- Store unhandled user messages
258
- """
259
- self.msg_user_processing = [] # processing user messages
260
- """
261
- 存储正在处理的用户信息
262
- Store working user messages
263
- """
264
-
265
- # * config
266
- self.enable_user_interaction = True
267
- self.enable_economy = True
268
- self.enable_social = True
269
-
270
- # * 信息提取
271
- self.retrive = {
272
- 'getfamilier': MemoryRetrive('Social', 'familiers', getfamilier)
273
- }
274
- """
275
- 记忆索引模块集合
276
- The collection of MemoryRetrive blocks
277
- - key (str(MemoryRetrive.user_func))
278
- - value (MemoryRetrive)
279
- """
280
-
281
- # * reason - 推理/判断功能
282
- self.reason = {
283
- 'idle': [
284
- MemoryReason("hasUserControl", hasUserControl),
285
- MemoryReason("startTrip", startTrip),
286
- MemoryReason("agent_message_handle_resp", handleConve, [self.retrive['getfamilier']]),
287
- MemoryReason("startConve", startConve),
288
- MemoryReason("startShop", startShop)
289
- ],
290
- 'trip': [
291
- MemoryReason("hasUserControl", hasUserControl),
292
- MemoryReason("routeFailed", routeFailed),
293
- MemoryReason("tripArrived", tripArrived)
294
- ],
295
- 'conve': [
296
- MemoryReason("hasUserControl", hasUserControl),
297
- MemoryReason("agent_message_handle_resp", handleConve, [self.retrive['getfamilier']]),
298
- MemoryReason("endConve", endConve),
299
- ],
300
- 'shop': [
301
- MemoryReason("hasUserControl", hasUserControl),
302
- MemoryReason("endShop", endShop)
303
- ],
304
- 'controled': [
305
- MemoryReason("endUserControl", endUserControl)
306
- ]
307
- }
308
- """
309
- 记忆推理模块集合
310
- The collection of MemoryReason blocks
311
- - key (str): state
312
- - value (list[MemoryReason])
313
- Notice: 根据Agent当前状态执行对应列表中的MemoryReason. Execute those corresponding MemoryReason blocks based on Agent's state
314
- """
315
-
316
- # * persistence - 记忆持久化
317
- self.persistence = [
318
- MemoryPersistence('Spatial', spacialPersistence)
319
- ]
320
- """
321
- 记忆持久化模块集合
322
- The collection of MemoryPersistence blocks
323
- """
324
-
325
- async def Forward(self):
326
- """
327
- WM主工作流
328
- The main workflow of WM
329
- - Reason
330
- - Persistence
331
- - (if need) Schedule
332
- """
333
- await self.runReason()
334
- await self.runPersistence()
335
- if self.has_user_command:
336
- ret = await self.scheduler.schedule(self.current_target)
337
- if ret != 0:
338
- self.Reason['hasUserControl'] = False
339
- self._agent.Hub.Update([AgentMessage(self._agent.Hub._agent_id, int(time.time()*1000), '抱歉,行程规划失败,请重试', None, None)])
340
- self.has_user_command = False
341
- await self.scheduler.schedule_forward()
342
- if not self.scheduler.is_controled:
343
- self.current_target = None
344
-
345
- async def senceReceive(self, sence):
346
- """
347
- 获取Sence结果的接口
348
- The interface used for receiving sence contents
349
- """
350
- self.sence = sence
351
- # * social message
352
- social_message = sence['social_messages']
353
- for message in social_message:
354
- print(message)
355
- from_id = message['from']
356
- content = message['message']
357
- if from_id in self.msg_agent_unhandle.keys():
358
- self.msg_agent_unhandle[from_id] += [{
359
- 'role': 'user',
360
- 'content': content
361
- }]
362
- else:
363
- self.msg_agent_unhandle[from_id] = [{
364
- 'role': 'user',
365
- 'content': content
366
- }]
367
- # * user message
368
- self.msg_user_unhandle = sence['user_messages']
369
-
370
- async def runReason(self):
371
- '''推理模块执行'''
372
- reason_line = self.reason[self._agent.state]
373
- for reason in reason_line:
374
- if reason.retrives == None:
375
- self.Reason[reason.out] = await reason.user_func(self)
376
- else:
377
- retrives = {}
378
- for retrive in reason.retrives:
379
- retrives[retrive.out] = await retrive.user_func(getattr(self.LTM, retrive.source))
380
- self.Reason[reason.out] = await reason.user_func(self, retrives)
381
-
382
- async def runPersistence(self):
383
- '''持久化模块执行'''
384
- for persis in self.persistence:
385
- mem = getattr(self._agent.Brain.Memory, persis.target)
386
- await persis.user_func(self, mem)
387
-
388
- def set_user_converse_background(self):
389
- self.user_converse_buffer[2]['content'] = self._agent.Image.get_profile()
390
-
391
- @property
392
- def LTM(self):
393
- return self._agent.Brain.Memory
394
-
395
- class SpatialMemory(Memory):
396
- """
397
- 空间记忆 (LTM)
398
- SpatialMemory (LTM)
399
-
400
- 空间记忆以location_node为基本组织单位, 每一个node被组织为一个dict, 包含以下属性
401
- The based unit of Spatial Memory is location_node, each node is presented as a dict, including following attributes:
402
- - id (int): the id of target location, '700426179' for instance
403
- - name (str): the name of target location, '清华大学' for instance
404
- - category (str): the category of target location, '教育学校' for instance
405
- - aoi_id (int): the related AOI's id, '500000011' for instance
406
- - relation (str): the relation between Agent and the location, '我在这里任职' for instance
407
- """
408
- def __init__(self, agent) -> None:
409
- super().__init__(agent, MemoryType.LTM)
410
- self.constant = []
411
- """
412
- 以列表形式存储的空间记忆: 基于文件载入的
413
- Spatial Memory in list: based on the MemoryLoad
414
- list[location_node]
415
- """
416
- self.sence = []
417
- """
418
- 以列表形式存储的空间记忆: 基于Sence结果
419
- Spatial Memory in list: based on the Sence
420
- list[location_node]
421
- """
422
- self.spatial_dict = {}
423
- """
424
- 以字典形式存储的空间记忆: key为id, value未node
425
- Spatial Memory in dict collection
426
- - key: id
427
- - value: location_node
428
- """
429
-
430
- def Forward(self, x:list, to_constant:bool = False):
431
- """
432
- 将输入内容x存储到记忆中
433
- Store x to spatial memory
434
-
435
- Args:
436
- - x (list): spatial nodes in list
437
- - to_constant (bool): whether store to constant, if False, only store to sence buffer, default False
438
- """
439
- for loc in x:
440
- self.spatial_dict[loc['id']] = loc
441
- self.sence += x
442
- if to_constant:
443
- self.constant += x
444
-
445
- def MemoryLoad(self, file_name:str):
446
- """
447
- 基于文件载入空间记忆
448
- Load Spatial Memory based on static file
449
-
450
- Args:
451
- - file_name (str): the path of file name
452
- """
453
- try:
454
- with open(file_name, 'r') as f:
455
- data = json.load(f)
456
- for loc in data:
457
- self.spatial_dict[loc['id']] = loc
458
- self.constant += data
459
- print("Load Succes.")
460
- except:
461
- print("Can't load spatial knowledge.")
462
-
463
- def MemorySave(self, file_name:str):
464
- """
465
- 将空间记忆存储为文件
466
- Store Spatial Memory to file
467
- Notice: only stores those in constant
468
-
469
- Args:
470
- - file_name (str): the file name
471
- """
472
- with open(file_name, 'w') as f:
473
- json.dumps(self.constant, f)
474
-
475
- def to_dialog_str(self):
476
- """
477
- 将空间信息转换为LLM可理解的文本
478
- Transfer Spatial Memory to LLM unstandable text
479
- """
480
- temp = self.constant + self.sence
481
- return json.dumps(temp, indent=0)
482
-
483
- class SocialMemory(Memory):
484
- """
485
- 社交记忆 (LTM)
486
- Social Memory (LTM)
487
-
488
- 社交记忆以person_node为基本组织单位, 每一个node被组织为一个dict, 包含以下属性
489
- The based unit of Social Memory is person_node, each node is presented as a dict, including following attributes:
490
- - id (int): person_id, '8' for instance
491
- - name (str): the name of person, '张三' for instance
492
- - relation (str): the relation between Agent and the target person, '亲密朋友' for instance
493
- - learned (str): the information that Agent learned about the target person, '他最近在学习AI' for instance
494
- """
495
- def __init__(self, agent) -> None:
496
- super().__init__(agent, MemoryType.LTM)
497
- self.familiers = []
498
- """
499
- 以列表形式存储社交记忆
500
- The Social Memory in list collection
501
- list[person_node]
502
- """
503
- self.familiers_dict = {}
504
- """
505
- 以字典形式存储的社交记忆
506
- The Social Memory in dict collection
507
- - key: person_id
508
- - value: person node
509
- """
510
-
511
- def MemoryLoad(self, file_name:str):
512
- """
513
- 基于文件的社交记忆加载
514
- Load Social Memory based on file
515
-
516
- Args:
517
- - file_name (str): the path of file
518
- """
519
- with open(file_name, 'r') as f:
520
- persons = json.load(f)
521
- for person in persons:
522
- self.familiers_dict[person['id']] = person
523
- self.familiers += persons
524
-
525
- def MemorySave(self, file_name:str):
526
- """
527
- 将社交记忆存储为文件
528
- Store Social Memory to file
529
-
530
- Args:
531
- - file_name (str): the path of file
532
- """
533
- with open(file_name, 'w') as f:
534
- json.dumps(self.familiers, f)
535
-
536
- def to_dialog_str(self):
537
- """
538
- 将社交记忆转化为LLM可理解的文本
539
- Transfer the Social Memory to LLM understandable text
540
- """
541
- return json.dumps(self.familiers, indent=0)
@@ -1 +0,0 @@
1
- '''社交记忆持久化'''
@@ -1,14 +0,0 @@
1
- '''空间记忆持久化'''
2
- async def spacialPersistence(wm, sp):
3
- if wm.sence != None:
4
- sence_buffer = wm.sence
5
- poi_list = []
6
- for poi in sence_buffer['pois']:
7
- poi_info = poi[0]
8
- poi_id = poi_info['id']
9
- name = poi_info['name']
10
- category = poi_info['category']
11
- aoi_id = poi_info['aoi_id']
12
- m_p = {'id': poi_id, 'name': name, 'category': category, 'aoi_id': aoi_id, 'relation': '偶尔看到'}
13
- poi_list.append(m_p)
14
- sp.Forward(poi_list)
@@ -1,37 +0,0 @@
1
- from ..scheduler import *
2
-
3
- async def startShop(wk):
4
- """
5
- 是否开始购物
6
- Whether start shopping
7
-
8
- Args:
9
- - wk (WorkingMemory)
10
-
11
- Returns:
12
- - (bool): if True, start, else not
13
- """
14
- if not wk.enable_economy:
15
- return False
16
- now = wk.scheduler.now
17
- if now != None and now.type.value == ScheduleType.SHOP.value:
18
- if now.arrived and not now.finished:
19
- return True
20
- return False
21
-
22
- async def endShop(wk):
23
- """
24
- 判断是否结束购物
25
- Whether end shopping
26
-
27
- Args:
28
- - wk (WorkingMemory)
29
-
30
- Returns:
31
- - (bool): if True, stop, else not
32
- """
33
- now = wk.scheduler.now
34
- if now != None and now.type.value == ScheduleType.SHOP.value:
35
- if now.finished:
36
- return True
37
- return False