pycityagent 2.0.0a47__cp311-cp311-macosx_11_0_arm64.whl → 2.0.0a49__cp311-cp311-macosx_11_0_arm64.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. pycityagent/__init__.py +3 -2
  2. pycityagent/agent.py +109 -4
  3. pycityagent/cityagent/__init__.py +20 -0
  4. pycityagent/cityagent/bankagent.py +54 -0
  5. pycityagent/cityagent/blocks/__init__.py +20 -0
  6. pycityagent/cityagent/blocks/cognition_block.py +304 -0
  7. pycityagent/cityagent/blocks/dispatcher.py +78 -0
  8. pycityagent/cityagent/blocks/economy_block.py +356 -0
  9. pycityagent/cityagent/blocks/mobility_block.py +258 -0
  10. pycityagent/cityagent/blocks/needs_block.py +305 -0
  11. pycityagent/cityagent/blocks/other_block.py +103 -0
  12. pycityagent/cityagent/blocks/plan_block.py +309 -0
  13. pycityagent/cityagent/blocks/social_block.py +345 -0
  14. pycityagent/cityagent/blocks/time_block.py +116 -0
  15. pycityagent/cityagent/blocks/utils.py +66 -0
  16. pycityagent/cityagent/firmagent.py +75 -0
  17. pycityagent/cityagent/governmentagent.py +60 -0
  18. pycityagent/cityagent/initial.py +98 -0
  19. pycityagent/cityagent/memory_config.py +202 -0
  20. pycityagent/cityagent/nbsagent.py +92 -0
  21. pycityagent/cityagent/societyagent.py +291 -0
  22. pycityagent/memory/memory.py +0 -18
  23. pycityagent/message/messager.py +6 -3
  24. pycityagent/simulation/agentgroup.py +123 -37
  25. pycityagent/simulation/simulation.py +311 -316
  26. pycityagent/workflow/block.py +66 -1
  27. pycityagent/workflow/tool.py +9 -4
  28. {pycityagent-2.0.0a47.dist-info → pycityagent-2.0.0a49.dist-info}/METADATA +2 -2
  29. {pycityagent-2.0.0a47.dist-info → pycityagent-2.0.0a49.dist-info}/RECORD +33 -14
  30. {pycityagent-2.0.0a47.dist-info → pycityagent-2.0.0a49.dist-info}/LICENSE +0 -0
  31. {pycityagent-2.0.0a47.dist-info → pycityagent-2.0.0a49.dist-info}/WHEEL +0 -0
  32. {pycityagent-2.0.0a47.dist-info → pycityagent-2.0.0a49.dist-info}/entry_points.txt +0 -0
  33. {pycityagent-2.0.0a47.dist-info → pycityagent-2.0.0a49.dist-info}/top_level.txt +0 -0
@@ -1,8 +1,12 @@
1
+ from __future__ import annotations
1
2
  import asyncio
2
3
  import functools
3
4
  import inspect
4
5
  from collections.abc import Awaitable, Callable, Coroutine
5
- from typing import Any, Optional, Union
6
+ import json
7
+ from typing import Any, List, Optional, Union
8
+
9
+ from pyparsing import Dict
6
10
 
7
11
  from ..environment.simulator import Simulator
8
12
  from ..llm import LLM
@@ -139,6 +143,9 @@ def trigger_class():
139
143
 
140
144
  # Define a Block, similar to a layer in PyTorch
141
145
  class Block:
146
+ configurable_fields: List[str] = []
147
+ default_values: dict[str, Any] = {}
148
+
142
149
  def __init__(
143
150
  self,
144
151
  name: str,
@@ -157,6 +164,64 @@ class Block:
157
164
  trigger.initialize() # 立即初始化trigger
158
165
  self.trigger = trigger
159
166
 
167
+ def export_config(self) -> Dict[str, Optional[str]]:
168
+ return {
169
+ field: self.default_values.get(field, "default_value")
170
+ for field in self.configurable_fields
171
+ }
172
+
173
+ @classmethod
174
+ def export_class_config(cls) -> Dict[str, str]:
175
+ return {
176
+ field: cls.default_values.get(field, "default_value")
177
+ for field in cls.configurable_fields
178
+ }
179
+
180
+ @classmethod
181
+ def import_config(cls, config: Dict[str, str]) -> "Block":
182
+ instance = cls(name=config["name"])
183
+ for field, value in config["config"].items():
184
+ if field in cls.configurable_fields:
185
+ setattr(instance, field, value)
186
+
187
+ # 递归创建子Block
188
+ for child_config in config.get("children", []):
189
+ child_block = Block.import_config(child_config)
190
+ setattr(instance, child_block.name.lower(), child_block)
191
+
192
+ return instance
193
+
194
+ def load_from_config(self, config: Dict[str, List[Dict]]) -> None:
195
+ """
196
+ 使用配置更新当前Block实例的参数,并递归更新子Block。
197
+ """
198
+ # 更新当前Block的参数
199
+ for field in self.configurable_fields:
200
+ if field in config["config"]:
201
+ if config["config"][field] != "default_value":
202
+ setattr(self, field, config["config"][field])
203
+
204
+ def build_or_update_block(block_data: Dict) -> Block:
205
+ block_name = block_data["name"].lower()
206
+ existing_block = getattr(self, block_name, None)
207
+
208
+ if existing_block:
209
+ # 递归更新子Block
210
+ existing_block.load_from_config(block_data)
211
+ return existing_block
212
+ else:
213
+ # 创建新的子Block
214
+ block_cls = globals().get(block_data["name"])
215
+ if block_cls is None:
216
+ raise KeyError(f"Block class '{block_data['name']}' not found.")
217
+ block_instance = block_cls.import_config(block_data)
218
+ setattr(self, block_name, block_instance)
219
+ return block_instance
220
+
221
+ # 递归遍历子Block配置
222
+ for block_data in config.get("blocks", []):
223
+ build_or_update_block(block_data)
224
+
160
225
  async def forward(self):
161
226
  """
162
227
  Each block performs a specific reasoning task.
@@ -1,3 +1,4 @@
1
+ import asyncio
1
2
  import time
2
3
  from collections import defaultdict
3
4
  from collections.abc import Callable, Sequence
@@ -6,6 +7,7 @@ from typing import Any, Optional, Union
6
7
  from mlflow.entities import Metric
7
8
 
8
9
  from ..agent import Agent
10
+ from ..utils.decorators import lock_decorator
9
11
  from ..environment import (LEVEL_ONE_PRE, POI_TYPE_DICT, AoiService,
10
12
  PersonService)
11
13
  from ..workflow import Block
@@ -136,7 +138,7 @@ class SencePOI(Tool):
136
138
 
137
139
  class UpdateWithSimulator(Tool):
138
140
  def __init__(self) -> None:
139
- pass
141
+ self._lock = asyncio.Lock()
140
142
 
141
143
  async def _update_motion_with_sim(
142
144
  self,
@@ -160,6 +162,7 @@ class UpdateWithSimulator(Tool):
160
162
  except KeyError as e:
161
163
  continue
162
164
 
165
+ @lock_decorator
163
166
  async def __call__(
164
167
  self,
165
168
  ):
@@ -169,8 +172,9 @@ class UpdateWithSimulator(Tool):
169
172
 
170
173
  class ResetAgentPosition(Tool):
171
174
  def __init__(self) -> None:
172
- pass
175
+ self._lock = asyncio.Lock()
173
176
 
177
+ @lock_decorator
174
178
  async def __call__(
175
179
  self,
176
180
  aoi_id: Optional[int] = None,
@@ -194,7 +198,8 @@ class ExportMlflowMetrics(Tool):
194
198
  self._log_batch_size = log_batch_size
195
199
  # TODO: support other log types
196
200
  self.metric_log_cache: dict[str, list[Metric]] = defaultdict(list)
197
-
201
+ self._lock = asyncio.Lock()
202
+ @lock_decorator
198
203
  async def __call__(
199
204
  self,
200
205
  metric: Union[Sequence[Union[Metric, dict]], Union[Metric, dict]],
@@ -226,7 +231,7 @@ class ExportMlflowMetrics(Tool):
226
231
  _cache = _cache[batch_size:]
227
232
  if clear_cache:
228
233
  await self._clear_cache()
229
-
234
+ @lock_decorator
230
235
  async def _clear_cache(
231
236
  self,
232
237
  ):
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycityagent
3
- Version: 2.0.0a47
4
- Summary: LLM-based城市环境agent构建库
3
+ Version: 2.0.0a49
4
+ Summary: LLM-based city environment agent building library
5
5
  Author-email: Yuwei Yan <pinkgranite86@gmail.com>, Junbo Yan <yanjb20thu@gmali.com>, Jun Zhang <zhangjun990222@gmali.com>
6
6
  License: MIT License
7
7
 
@@ -1,13 +1,7 @@
1
- pycityagent-2.0.0a47.dist-info/RECORD,,
2
- pycityagent-2.0.0a47.dist-info/LICENSE,sha256=n2HPXiupinpyHMnIkbCf3OTYd3KMqbmldu1e7av0CAU,1084
3
- pycityagent-2.0.0a47.dist-info/WHEEL,sha256=DQkJubmXvyOE1DlaPsfq9czNuGB2yvzYGbMABjt_JVM,109
4
- pycityagent-2.0.0a47.dist-info/entry_points.txt,sha256=BZcne49AAIFv-hawxGnPbblea7X3MtAtoPyDX8L4OC4,132
5
- pycityagent-2.0.0a47.dist-info/top_level.txt,sha256=yOmeu6cSXmiUtScu53a3s0p7BGtLMaV0aff83EHCTic,43
6
- pycityagent-2.0.0a47.dist-info/METADATA,sha256=YwAfusA9UF3yJ6mdI8cVU81n5gZJISLcSK7dPiDE0W4,9125
7
1
  pycityagent/pycityagent-sim,sha256=n96jlVZRINlBec5SPOGAdUmeLWMoEKGgoH29iOVJ0wE,34081890
8
- pycityagent/__init__.py,sha256=fv0mzNGbHBF6m550yYqnuUpB8iQPWS-7EatYRK7DO4s,693
2
+ pycityagent/__init__.py,sha256=9sHyzo8monlBPDe7LTlxCIHeNPYj8HJJDCeuJrYJLsQ,750
9
3
  pycityagent/pycityagent-ui,sha256=cHZjqtrQ4Fh4qtRahFNCNbT2DNHLmUexiDAa-72Z3RQ,40333378
10
- pycityagent/agent.py,sha256=A40nN1xUJ6AqhoQ4pXt5yAehc15BYHwLMRpIGAmMLLc,30051
4
+ pycityagent/agent.py,sha256=iaF83y344V29-jghx5bJD3yY8kMuSzInBPNi7cVxYiA,34026
11
5
  pycityagent/metrics/mlflow_client.py,sha256=g_tHxWkWTDijtbGL74-HmiYzWVKb1y8-w12QrY9jL30,4449
12
6
  pycityagent/metrics/__init__.py,sha256=X08PaBbGVAd7_PRGLREXWxaqm7nS82WBQpD1zvQzcqc,128
13
7
  pycityagent/metrics/utils/const.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -18,7 +12,7 @@ pycityagent/llm/__init__.py,sha256=iWs6FLgrbRVIiqOf4ILS89gkVCTvS7HFC3vG-MWuyko,2
18
12
  pycityagent/llm/llm.py,sha256=owTYuXmnHZnvXaAvwiiyD511P3wpU3K04xZArhhiJF0,15700
19
13
  pycityagent/llm/embeddings.py,sha256=Nhf_tUIlaYJAZ93wW2QTCtS1wq7e8fUgdn2JketEAuQ,7600
20
14
  pycityagent/llm/utils.py,sha256=hoNPhvomb1u6lhFX0GctFipw74hVKb7bvUBDqwBzBYw,160
21
- pycityagent/memory/memory.py,sha256=UBh4yANNHDzYZwrsvyX4ZMSHXINbu1U6g0HLNCOOCk8,17883
15
+ pycityagent/memory/memory.py,sha256=RV54r9uE3H7RIfz5ifaeXiD7RrOJotxJNhAOguZrYUk,17273
22
16
  pycityagent/memory/profile.py,sha256=q8ZS9IBmHCg_X1GONUvXK85P6tCepTKQgXKuvuXYNXw,5203
23
17
  pycityagent/memory/__init__.py,sha256=_Vfdo1HcLWsuuz34_i8e91nnLVYADpMlHHSVaB3xgIk,297
24
18
  pycityagent/memory/memory_base.py,sha256=QG_j3BxZvkadFEeE3uBR_kjl_xcXD1aHUVs8GEF3d6w,5654
@@ -27,12 +21,12 @@ pycityagent/memory/utils.py,sha256=oJWLdPeJy_jcdKcDTo9JAH9kDZhqjoQhhv_zT9qWC0w,8
27
21
  pycityagent/memory/const.py,sha256=6zpJPJXWoH9-yf4RARYYff586agCoud9BRn7sPERB1g,932
28
22
  pycityagent/memory/faiss_query.py,sha256=Z0JS4udyPYCIzHMq464QtHscnswu35gh9fQptikAwkQ,12976
29
23
  pycityagent/memory/state.py,sha256=TYItiyDtehMEQaSBN7PpNrnNxdDM5jGppr9R9Ufv3kA,5134
30
- pycityagent/simulation/simulation.py,sha256=Vrt2hr9AsKG9VEwY90R9mmUR9TxifshUfSYpzW5LOXo,23317
24
+ pycityagent/simulation/simulation.py,sha256=7Y1r5DAFaB1vuDd3l_85NWpHQUy2GLkFEb800xsJr0E,25565
31
25
  pycityagent/simulation/__init__.py,sha256=P5czbcg2d8S0nbbnsQXFIhwzO4CennAhZM8OmKvAeYw,194
32
- pycityagent/simulation/agentgroup.py,sha256=-MnrM8pH7dyGTj2DL6TRH4AD9HsvEZ1dEF3xOfmbs_4,25933
26
+ pycityagent/simulation/agentgroup.py,sha256=DGN6q9S65K9gSv_ihBeT6iJ__LJhl27yXBFyLEk55t0,29302
33
27
  pycityagent/simulation/storage/pg.py,sha256=5itxKOkNPlOzN7z2_3oKU1ZK0uLTDugfld8ZkRbD69I,8407
34
28
  pycityagent/message/__init__.py,sha256=TCjazxqb5DVwbTu1fF0sNvaH_EPXVuj2XQ0p6W-QCLU,55
35
- pycityagent/message/messager.py,sha256=uKXArXOMZGK2fE86XiMtVrI_N0yTLA1EL3KdtCVK5uk,3217
29
+ pycityagent/message/messager.py,sha256=78K31EPKfC5IxbISc-Lc2babC7VOh9Vbe3c0sO-YDLA,3333
36
30
  pycityagent/utils/avro_schema.py,sha256=AlADbzV8FxiSfvhQhiX9KhrwMjrx0lGT-lED4TI1gJM,4152
37
31
  pycityagent/utils/__init__.py,sha256=xli0FuRffR9Wp4aRcMnlfeDHuGxB8Y5paDjyAt0UoeE,462
38
32
  pycityagent/utils/survey_util.py,sha256=Be9nptmu2JtesFNemPgORh_2GsN7rcDYGQS9Zfvc5OI,2169
@@ -45,8 +39,8 @@ pycityagent/utils/parsers/json_parser.py,sha256=tjwyPluYfkWgsvLi0hzfJwFhO3L6yQfZ
45
39
  pycityagent/cli/wrapper.py,sha256=2Tb52gOlEVgn11Ekt6ZkRXr_BGzte-EPyBKnR6g6hQ4,1143
46
40
  pycityagent/workflow/__init__.py,sha256=QNkUV-9mACMrR8c0cSKna2gC1mMZdxXbxWzjE-Uods0,621
47
41
  pycityagent/workflow/prompt.py,sha256=6jI0Rq54JLv3-IXqZLYug62vse10wTI83xvf4ZX42nk,2929
48
- pycityagent/workflow/block.py,sha256=C2aWdVRffb3LknP955GvPcBMsm3VPXN9ZuAtCgITFTo,7181
49
- pycityagent/workflow/tool.py,sha256=xADxhNgVsjNiMxlhdwn3xGUstFOkLEG8P67ez8VmwSI,8555
42
+ pycityagent/workflow/block.py,sha256=8pK17DGX8MnFJHq5lJ4susdZ-CDAEIjlTV_2mJxhbbw,9600
43
+ pycityagent/workflow/tool.py,sha256=ChuN5Sm-yltesemewjnTOYaxN6NUjfi2MezVuclf6Tc,8776
50
44
  pycityagent/workflow/trigger.py,sha256=Df-MOBEDWBbM-v0dFLQLXteLsipymT4n8vqexmK2GiQ,5643
51
45
  pycityagent/environment/__init__.py,sha256=awHxlOud-btWbk0FCS4RmGJ13W84oVCkbGfcrhKqihA,240
52
46
  pycityagent/environment/simulator.py,sha256=1OUfODDzM4EN6Lw_Wzq4KeQb-EpcUBioZYc9fxfSPn0,12070
@@ -76,6 +70,31 @@ pycityagent/environment/sim/clock_service.py,sha256=fgYXacf_-ixhVAn5uKUvqvemBS6A
76
70
  pycityagent/environment/sim/road_service.py,sha256=bKyn3_me0sGmaJVyF6eNeFbdU-9C1yWsa9L7pieDJzg,1285
77
71
  pycityagent/environment/interact/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
78
72
  pycityagent/environment/interact/interact.py,sha256=ifxPPzuHeqLHIZ_6zvfXMoBOnBsXNIP4bYp7OJ7pnEQ,6588
73
+ pycityagent/cityagent/memory_config.py,sha256=tI4SbzDdjVqIt5cTqx-CwNHu0xnbVAhIenZgwYa9wf8,10429
74
+ pycityagent/cityagent/bankagent.py,sha256=IC4Qf-zgHg9Q65ecb_UAKjw-HbizYEDuzfhlPIske9Y,2166
75
+ pycityagent/cityagent/__init__.py,sha256=gcBQ-a50XegFtjigQ7xDXRBZrywBKqifiQFSRnEF8gM,572
76
+ pycityagent/cityagent/firmagent.py,sha256=cV2X1wtj6vbXEGNcFlhb9Nsp544coe2lyEjLwOmLOPE,3635
77
+ pycityagent/cityagent/nbsagent.py,sha256=VFxz0FsjPN9hAir-VxXYVE8WR4zsEXF7oRn0G8SYNfo,4647
78
+ pycityagent/cityagent/initial.py,sha256=_sKZicZ0wfuBN_hLOW82_Yp3wOMMlygEvcGT0sYXE6c,4538
79
+ pycityagent/cityagent/societyagent.py,sha256=-O_lk2xk9-ldE9MTX48tqbRyJFIqcpYnmfMsrGUvRvw,13958
80
+ pycityagent/cityagent/governmentagent.py,sha256=WdM-80YkRohYuNj1hB07ZZ_dgRN_uiVU8YkoS7Cs6vg,2713
81
+ pycityagent/cityagent/blocks/dispatcher.py,sha256=mEa1r3tRS3KI1BMZR_w_sbUGzOj6aUJuiUrsHv1n2n0,2943
82
+ pycityagent/cityagent/blocks/needs_block.py,sha256=pPPjdVFCqFvAV0RM1LVevQIH5d0GALnB6xLekvplutE,13113
83
+ pycityagent/cityagent/blocks/cognition_block.py,sha256=CGIYwuF1twS5g3DNhCkaSFT2s1IQXF5NjJO38EX6FLg,15633
84
+ pycityagent/cityagent/blocks/time_block.py,sha256=M7ng1jQ14gz4Xle0DC-kWeZmetq9lYQ2HzgEgsu-eX8,4337
85
+ pycityagent/cityagent/blocks/social_block.py,sha256=AkI9wLm9WUEFe5Hc5uDfLfwJtWe1TpLLsWdjm__9KM0,14012
86
+ pycityagent/cityagent/blocks/__init__.py,sha256=j8aKIrSEkoMjoWKPQbyRqmeHaB-bjaJObyfrEagq8MI,503
87
+ pycityagent/cityagent/blocks/economy_block.py,sha256=yysi4E_k47sNmeMorbHVJydYymyTqo9J6hdQnzJ4HN8,20793
88
+ pycityagent/cityagent/blocks/utils.py,sha256=BYf15pDynAQw8eeXyn1iVfVDDdkkoRz9e6eiSGUnz4g,2031
89
+ pycityagent/cityagent/blocks/other_block.py,sha256=ETgtj_EpYbAocIJq12LB-SPcHAY-b7TRsm9llo3ZIrc,3845
90
+ pycityagent/cityagent/blocks/plan_block.py,sha256=Ad_K2m0gYwH5qJi1HOETgEe83uRX06TXconAR8RIZHU,11479
91
+ pycityagent/cityagent/blocks/mobility_block.py,sha256=ZebloDhvZJYbV0YSWhAbnOLToiL-4fG7vKNq3kh37M4,10788
79
92
  pycityagent/survey/models.py,sha256=YE50UUt5qJ0O_lIUsSY6XFCGUTkJVNu_L1gAhaCJ2fs,3546
80
93
  pycityagent/survey/__init__.py,sha256=rxwou8U9KeFSP7rMzXtmtp2fVFZxK4Trzi-psx9LPIs,153
81
94
  pycityagent/survey/manager.py,sha256=S5IkwTdelsdtZETChRcfCEczzwSrry_Fly9MY4s3rbk,1681
95
+ pycityagent-2.0.0a49.dist-info/RECORD,,
96
+ pycityagent-2.0.0a49.dist-info/LICENSE,sha256=n2HPXiupinpyHMnIkbCf3OTYd3KMqbmldu1e7av0CAU,1084
97
+ pycityagent-2.0.0a49.dist-info/WHEEL,sha256=DQkJubmXvyOE1DlaPsfq9czNuGB2yvzYGbMABjt_JVM,109
98
+ pycityagent-2.0.0a49.dist-info/entry_points.txt,sha256=BZcne49AAIFv-hawxGnPbblea7X3MtAtoPyDX8L4OC4,132
99
+ pycityagent-2.0.0a49.dist-info/top_level.txt,sha256=yOmeu6cSXmiUtScu53a3s0p7BGtLMaV0aff83EHCTic,43
100
+ pycityagent-2.0.0a49.dist-info/METADATA,sha256=AArJCX11voHGW5AlMrin1qZoj8iVGdOD9XLODRcQwUY,9139