pycityagent 2.0.0a95__cp39-cp39-macosx_11_0_arm64.whl → 2.0.0a97__cp39-cp39-macosx_11_0_arm64.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.
@@ -260,20 +260,16 @@ class Agent(ABC):
260
260
  - Recursively updates or creates top-level Blocks as specified in the configuration.
261
261
  - Raises a `KeyError` if a required Block is not found in the agent.
262
262
  """
263
- # 使用配置更新当前Agent实例的Block层次结构。
264
- # 更新当前Agent的基础参数
265
263
  for field in self.configurable_fields:
266
264
  if field in config["config"]:
267
265
  if config["config"][field] != "default_value":
268
266
  setattr(self, field, config["config"][field])
269
267
 
270
- # 递归更新或创建顶层Block
271
268
  for block_data in config.get("blocks", []):
272
269
  block_name = block_data["name"]
273
270
  existing_block = getattr(self, block_name, None) # type:ignore
274
271
 
275
272
  if existing_block:
276
- # 如果Block已经存在,则递归更新
277
273
  existing_block.load_from_config(block_data)
278
274
  else:
279
275
  raise KeyError(
@@ -13,9 +13,10 @@ from pycityagent.llm import LLM
13
13
  from pycityagent.memory import Memory
14
14
  from pycityagent.workflow.block import Block
15
15
  from pycityagent.workflow.prompt import FormatPrompt
16
-
16
+ from .utils import clean_json_response
17
17
  from .dispatcher import BlockDispatcher
18
18
 
19
+
19
20
  logger = logging.getLogger("pycityagent")
20
21
 
21
22
 
@@ -166,10 +167,11 @@ class PlaceSelectionBlock(Block):
166
167
  )
167
168
  levelOneType = await self.llm.atext_request(self.typeSelectionPrompt.to_dialog(), response_format={"type": "json_object"}) # type: ignore
168
169
  try:
170
+ levelOneType = clean_json_response(levelOneType)
169
171
  levelOneType = json.loads(levelOneType)["place_type"]
170
172
  sub_category = poi_cate[levelOneType]
171
173
  except Exception as e:
172
- logger.warning(f"Wrong type of poi, raw response: {levelOneType}")
174
+ logger.warning(f"Level One Type Selection: wrong type of poi, raw response: {levelOneType}")
173
175
  levelOneType = random.choice(list(poi_cate.keys()))
174
176
  sub_category = poi_cate[levelOneType]
175
177
  self.secondTypeSelectionPrompt.format(
@@ -177,9 +179,10 @@ class PlaceSelectionBlock(Block):
177
179
  )
178
180
  levelTwoType = await self.llm.atext_request(self.secondTypeSelectionPrompt.to_dialog(), response_format={"type": "json_object"}) # type: ignore
179
181
  try:
182
+ levelTwoType = clean_json_response(levelTwoType)
180
183
  levelTwoType = json.loads(levelTwoType)["place_type"]
181
184
  except Exception as e:
182
- logger.warning(f"Wrong type of poi, raw response: {levelTwoType}")
185
+ logger.warning(f"Level Two Type Selection: wrong type of poi, raw response: {levelTwoType}")
183
186
  levelTwoType = random.choice(sub_category)
184
187
  center = await self.memory.status.get("position")
185
188
  center = (center["xy_position"]["x"], center["xy_position"]["y"])
@@ -260,19 +263,18 @@ class MoveBlock(Block):
260
263
  self.placeAnalysisPrompt = FormatPrompt(PLACE_ANALYSIS_PROMPT)
261
264
 
262
265
  async def forward(self, step, context):
263
- # 这里应该添加移动的具体逻辑
264
266
  agent_id = await self.memory.status.get("id")
265
267
  self.placeAnalysisPrompt.format(
266
268
  plan=context["plan"], intention=step["intention"]
267
269
  )
268
270
  response = await self.llm.atext_request(self.placeAnalysisPrompt.to_dialog(), response_format={"type": "json_object"}) # type: ignore
269
271
  try:
272
+ response = clean_json_response(response)
270
273
  response = json.loads(response)["place_type"]
271
274
  except Exception as e:
272
- logger.warning(f"Wrong type of poi, raw response: {response}")
275
+ logger.warning(f"Place Analysis: wrong type of place, raw response: {response}")
273
276
  response = "home"
274
277
  if response == "home":
275
- # 返回到家
276
278
  home = await self.memory.status.get("home")
277
279
  home = home["aoi_position"]["aoi_id"]
278
280
  nowPlace = await self.memory.status.get("position")
@@ -8,6 +8,7 @@ from pycityagent.llm import LLM
8
8
  from pycityagent.memory import Memory
9
9
  from pycityagent.workflow.block import Block
10
10
  from pycityagent.workflow.prompt import FormatPrompt
11
+ from .utils import clean_json_response
11
12
 
12
13
  logger = logging.getLogger("pycityagent")
13
14
 
@@ -126,7 +127,7 @@ class NeedsBlock(Block):
126
127
  now_time=await self.simulator.get_time(format_time=True),
127
128
  )
128
129
  response = await self.llm.atext_request(self.initial_prompt.to_dialog(), response_format={"type": "json_object"})
129
- response = self.clean_json_response(response)
130
+ response = clean_json_response(response)
130
131
  retry = 3
131
132
  while retry > 0:
132
133
  try:
@@ -309,7 +310,7 @@ class NeedsBlock(Block):
309
310
  while retry > 0:
310
311
  response = await self.llm.atext_request(self.evaluation_prompt.to_dialog(), response_format={"type": "json_object"})
311
312
  try:
312
- new_satisfaction = json.loads(self.clean_json_response(response)) # type: ignore
313
+ new_satisfaction = json.loads(clean_json_response(response)) # type: ignore
313
314
  # 更新所有需求的数值
314
315
  for need_type, new_value in new_satisfaction.items():
315
316
  if need_type in [
@@ -330,11 +331,6 @@ class NeedsBlock(Block):
330
331
  logger.warning(f"Original response: {response}")
331
332
  retry -= 1
332
333
 
333
- def clean_json_response(self, response: str) -> str:
334
- """清理LLM响应中的特殊字符"""
335
- response = response.replace("```json", "").replace("```", "")
336
- return response.strip()
337
-
338
334
  async def forward(self):
339
335
  await self.initialize()
340
336
 
@@ -10,7 +10,7 @@ from pycityagent.llm import LLM
10
10
  from pycityagent.memory import Memory
11
11
  from pycityagent.workflow import Block
12
12
  from pycityagent.workflow.prompt import FormatPrompt
13
-
13
+ from .utils import clean_json_response
14
14
  logger = logging.getLogger("pycityagent")
15
15
 
16
16
  GUIDANCE_SELECTION_PROMPT = """As an intelligent agent's decision system, please select the most suitable option from the following choices to satisfy the current need.
@@ -203,7 +203,7 @@ class PlanBlock(Block):
203
203
  retry = 3
204
204
  while retry > 0:
205
205
  try:
206
- result = json.loads(self.clean_json_response(response)) # type: ignore
206
+ result = json.loads(clean_json_response(response)) # type: ignore
207
207
  if "selected_option" not in result or "evaluation" not in result:
208
208
  raise ValueError("Invalid guidance selection format")
209
209
  if (
@@ -255,7 +255,7 @@ class PlanBlock(Block):
255
255
  retry = 3
256
256
  while retry > 0:
257
257
  try:
258
- result = json.loads(self.clean_json_response(response)) # type: ignore
258
+ result = json.loads(clean_json_response(response)) # type: ignore
259
259
  if (
260
260
  "plan" not in result
261
261
  or "target" not in result["plan"]
@@ -316,8 +316,3 @@ Execution Steps: \n{formated_steps}
316
316
  "current_step", steps[0] if steps else {"intention": "", "type": ""}
317
317
  )
318
318
  await self.memory.status.update("execution_context", {"plan": formated_plan})
319
-
320
- def clean_json_response(self, response: str) -> str:
321
- """Clean special characters in LLM response"""
322
- response = response.replace("```json", "").replace("```", "")
323
- return response.strip()
@@ -57,6 +57,6 @@ def extract_dict_from_string(input_string):
57
57
 
58
58
 
59
59
  def clean_json_response(response: str) -> str:
60
- """清理LLM响应中的特殊字符"""
60
+ """remove the special characters in the response"""
61
61
  response = response.replace("```json", "").replace("```", "")
62
- return response.strip()
62
+ return response.strip()
@@ -29,7 +29,7 @@ class AgentConfig(BaseModel):
29
29
  number_of_nbs: int = Field(1, description="Number of neighborhood-based services")
30
30
  group_size: int = Field(100, description="Size of agent groups")
31
31
  embedding_model: Any = Field(None, description="Embedding model")
32
- agent_class_configs: Optional[dict[Any, dict[str, list[dict]]]] = None
32
+ agent_class_configs: Optional[dict[Any, dict[str, Any]]] = None
33
33
  memory_config_func: Optional[dict[type["Any"], Callable]] = None
34
34
  memory_config_init_func: Optional[Callable] = Field(None)
35
35
  init_func: Optional[list[Callable[["AgentSimulation"], None]]] = None
@@ -47,7 +47,7 @@ class AgentConfig(BaseModel):
47
47
  number_of_nbs: int = 1,
48
48
  group_size: int = 100,
49
49
  embedding_model: Any = None,
50
- agent_class_configs: Optional[dict[Any, dict[str, list[dict]]]] = None,
50
+ agent_class_configs: Optional[dict[Any, dict[str, Any]]] = None,
51
51
  enable_institution: bool = True,
52
52
  memory_config_func: Optional[dict[type["Any"], Callable]] = None,
53
53
  memory_config_init_func: Optional[Callable] = None,
@@ -192,7 +192,7 @@ class AgentGroup:
192
192
  self.agent_config_file is not None
193
193
  and self.agent_config_file[agent_class_i]
194
194
  ):
195
- agent.load_from_file(self.agent_config_file[agent_class_i])
195
+ agent.load_from_config(self.agent_config_file[agent_class_i])
196
196
  if self._message_interceptor is not None:
197
197
  agent.set_message_interceptor(self._message_interceptor)
198
198
  self.agents.append(agent)
@@ -374,7 +374,7 @@ class AgentSimulation:
374
374
  await simulation.pause_simulator()
375
375
  elif step.type == WorkflowType.RESUME:
376
376
  await simulation.resume_simulator()
377
- elif step.type == WorkflowType.FUNCTION:
377
+ else:
378
378
  _func = cast(Callable, step.func)
379
379
  await _func(simulation)
380
380
  logger.info("Simulation finished")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pycityagent
3
- Version: 2.0.0a95
3
+ Version: 2.0.0a97
4
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
@@ -1,3 +1,9 @@
1
+ pycityagent-2.0.0a97.dist-info/RECORD,,
2
+ pycityagent-2.0.0a97.dist-info/LICENSE,sha256=n2HPXiupinpyHMnIkbCf3OTYd3KMqbmldu1e7av0CAU,1084
3
+ pycityagent-2.0.0a97.dist-info/WHEEL,sha256=md3JO_ifs5j508p3TDNMgtQVtnQblpGEt_Wo4W56l8Y,107
4
+ pycityagent-2.0.0a97.dist-info/entry_points.txt,sha256=BZcne49AAIFv-hawxGnPbblea7X3MtAtoPyDX8L4OC4,132
5
+ pycityagent-2.0.0a97.dist-info/top_level.txt,sha256=yOmeu6cSXmiUtScu53a3s0p7BGtLMaV0aff83EHCTic,43
6
+ pycityagent-2.0.0a97.dist-info/METADATA,sha256=M8Yf50T1rDcPjB8_SoCuFSONew2E-mMI-D-Y2aomCbo,8657
1
7
  pycityagent/pycityagent-sim,sha256=_xsIrY1raLYagebaymahAZc2YSustRmQM2jm1B4p27U,36972738
2
8
  pycityagent/__init__.py,sha256=PUKWTXc-xdMG7px8oTNclodsILUgypANj2Z647sY63k,808
3
9
  pycityagent/pycityagent-ui,sha256=Ur95yZygIaZ5l_CDqP9394M5GQ66iV5PkcNPYFWqzvk,41225346
@@ -18,9 +24,9 @@ pycityagent/memory/utils.py,sha256=oJWLdPeJy_jcdKcDTo9JAH9kDZhqjoQhhv_zT9qWC0w,8
18
24
  pycityagent/memory/const.py,sha256=Wgsx0oztDrJDEpI9Dr6XeI6GXrABcP0UTOuEvMp1AD8,934
19
25
  pycityagent/memory/faiss_query.py,sha256=KPeyzIjD0dzkxr-TlOeCiIlkdh1WAyyipCAXUEt97Lk,17350
20
26
  pycityagent/memory/state.py,sha256=JFCBuK1AS-HqscvdGS9ATF9AUU8t29_2leDY_6iO2_4,5158
21
- pycityagent/simulation/simulation.py,sha256=GrD5VWaEvrKrBFwhEKUUfQfk2rweTEZnROaBZJXSni0,47134
27
+ pycityagent/simulation/simulation.py,sha256=YPRzB7wCL-K85W3hgvBWukefyEgZXZCi4egH6rZa6XA,47099
22
28
  pycityagent/simulation/__init__.py,sha256=u1WpgwVxPboXWMxrUQKMXJNmTKQYAeCaqZv9HmSxESY,118
23
- pycityagent/simulation/agentgroup.py,sha256=JFDEywmFziq-I8aUDZ3QhVD8cXliVsUSav482BmPDO4,36812
29
+ pycityagent/simulation/agentgroup.py,sha256=DYx68TckA5ox9x_GHID-3Gg19qABY-NR9QAO2BKKfMc,36814
24
30
  pycityagent/simulation/storage/pg.py,sha256=xRshSOGttW-p0re0fNBOjOpb-nQ5msIE2LsdT79_E_Y,8425
25
31
  pycityagent/message/message_interceptor.py,sha256=Z7I1vqs4BrKadPAtQi-nfbkgboBAflXDSIcbIpDAxB8,17777
26
32
  pycityagent/message/__init__.py,sha256=f5QH7DKPqEAMyfSlBMnl3uouOKlsoel909STlIe7nUk,276
@@ -35,7 +41,7 @@ pycityagent/utils/parsers/__init__.py,sha256=AN2xgiPxszWK4rpX7zrqRsqNwfGF3WnCA5-
35
41
  pycityagent/utils/parsers/code_block_parser.py,sha256=jy6wHx9zypvJTWneCKuUaLQL19d4yLK6C_awc7y8A-k,1179
36
42
  pycityagent/utils/parsers/parser_base.py,sha256=ZbqRcqOBL9hfHVZSltQSQmJnWrtuJS9aYeOJU-FlJ0E,1725
37
43
  pycityagent/utils/parsers/json_parser.py,sha256=sakKohUuMcUH2toR85CAG_37D02ZoAn6LlzLgftUjmo,2923
38
- pycityagent/agent/agent_base.py,sha256=MM_kBWheTk9Y3pKoDo6Yl1Bvn2usT6v2icloYx_ykCM,39467
44
+ pycityagent/agent/agent_base.py,sha256=Fmp9wYwiDskEQxslweO3Jc-1OwbB9vgjv1VfZZIHSGI,39252
39
45
  pycityagent/agent/__init__.py,sha256=U20yKu9QwSqAx_PHk5JwipfODkDfxONtumVfnsKjWFg,180
40
46
  pycityagent/agent/agent.py,sha256=zJs09Tzz53av59SzmrlJj6Yd-XId6voCYaxguLbbq3s,18991
41
47
  pycityagent/cli/wrapper.py,sha256=bAwmfWTXbGld-uiMnIMhKp22IVRQjhLUToknyUDk9rQ,1147
@@ -43,7 +49,7 @@ pycityagent/workflow/__init__.py,sha256=WVBMF-UT3iOBoyFihRrkeqAyLvD_Iibn2axAPOIM
43
49
  pycityagent/workflow/prompt.py,sha256=rzenP4EFGxbWE1aq-x2036b6umKvi5cQx2xtWULwgIk,3392
44
50
  pycityagent/workflow/block.py,sha256=phr5julVru-Yv-oWyUNMNmm4okhPMNZIF7Up71aoUY0,12249
45
51
  pycityagent/workflow/trigger.py,sha256=4nzAwywGQsFabgo6gzp-vD2EV4wII7Z0LHGEAsflSEY,7608
46
- pycityagent/configs/exp_config.py,sha256=D_OyUBxBx-I5Eyaot52Kl6hb5wEvF5CjwcBUDM6agG8,7319
52
+ pycityagent/configs/exp_config.py,sha256=5cVEfCgBQIXNeidXttvRw31wDIlksWGiwcB0JbyHMb8,7305
47
53
  pycityagent/configs/__init__.py,sha256=JAvFkZ6yKTtWvkgO2FaeQfpR-NsStDZPadLH9FOIROU,486
48
54
  pycityagent/configs/utils.py,sha256=ILVL5wjLJqxyBVGkV1QOkqp4b9EulSmNrNbD0JQIVqc,429
49
55
  pycityagent/configs/sim_config.py,sha256=cCdVu0IypmyOEeWiOLsocL7y7d8uBnLjXsH4_t-pXDk,8209
@@ -81,21 +87,15 @@ pycityagent/cityagent/societyagent.py,sha256=z1i7yPRz7Uupw5oGpMlFwyDi-8R4wHSCjgh
81
87
  pycityagent/cityagent/message_intercept.py,sha256=Am0u-hGFOBcvcNXE_WJos5iwh2QoJLihdSIz3sr_U9Y,4439
82
88
  pycityagent/cityagent/governmentagent.py,sha256=P3ufIfM5ldh2KC9y_y1ONowsV3FsFF5LWe0iQ3MVmgA,3067
83
89
  pycityagent/cityagent/blocks/dispatcher.py,sha256=gd3lyggvtkCq9Ou_icgua60H0UjHTzwHoynLl_iZoes,2939
84
- pycityagent/cityagent/blocks/needs_block.py,sha256=PDReR1GjF3qafR06Wfw_mizzBZ6xRQRq6KqgA9r8WOA,15321
90
+ pycityagent/cityagent/blocks/needs_block.py,sha256=1Mnr2vStBxSbmh2WByJdefOvTToKOENYDhyZFuL0KiM,15142
85
91
  pycityagent/cityagent/blocks/cognition_block.py,sha256=vy7wEvK72-sOieSSWidIXd5nKPLR-4f-ZYL7gyvje-0,15552
86
92
  pycityagent/cityagent/blocks/social_block.py,sha256=C1zMcN3RZBYewqw0MEYgtTf5Jzsol1Up3Ew9ovTSm1Y,15169
87
93
  pycityagent/cityagent/blocks/__init__.py,sha256=Tmy1CyQ8s3Iltp4xYWNg73Y28UWQv_LNWgMzgzquQT0,420
88
94
  pycityagent/cityagent/blocks/economy_block.py,sha256=w1rbTb4CqqXD9BDQuOAtCmrJ4KJjJYiQ5hJHEmCs6CA,20924
89
- pycityagent/cityagent/blocks/utils.py,sha256=YQkthaMkSCnT-1yfOkioGDvi2c-NLc5B-08BBlW4z0k,1781
95
+ pycityagent/cityagent/blocks/utils.py,sha256=dNIQGv7Br3hWOFznW1JRrFVeGw2vn3QRiPq732we5kQ,1792
90
96
  pycityagent/cityagent/blocks/other_block.py,sha256=-H2umOQ-l7_9SjP-SHu7J4oHDh4V-r649_4kGS9Qrng,4447
91
- pycityagent/cityagent/blocks/plan_block.py,sha256=-3ww7WPzEoDHXJp_WRudllL9GphAQw_-nR426OUEiGY,11897
92
- pycityagent/cityagent/blocks/mobility_block.py,sha256=rrWzJO6mCMxUFfl1txOqq9BY7FmQ3LE3-Kr0d-4jnCc,16669
97
+ pycityagent/cityagent/blocks/plan_block.py,sha256=3TfXg6Iqa9Z_fh22KV2ZLNffNFglIV22vgCfGmorNe4,11710
98
+ pycityagent/cityagent/blocks/mobility_block.py,sha256=bUoExMdxlMzbnWHe1hx6bkR2Jjc1CZglux8RAXrWaRE,16876
93
99
  pycityagent/survey/models.py,sha256=g3xni4GcA1Py3vlGt6z4ltutjgQ4G0uINYAM8vKRJAw,5225
94
100
  pycityagent/survey/__init__.py,sha256=rxwou8U9KeFSP7rMzXtmtp2fVFZxK4Trzi-psx9LPIs,153
95
101
  pycityagent/survey/manager.py,sha256=QZEApC6tKe-g1waDa_O4Eg4CFkyL8KWa7tUGZnT_7WI,3397
96
- pycityagent-2.0.0a95.dist-info/RECORD,,
97
- pycityagent-2.0.0a95.dist-info/LICENSE,sha256=n2HPXiupinpyHMnIkbCf3OTYd3KMqbmldu1e7av0CAU,1084
98
- pycityagent-2.0.0a95.dist-info/WHEEL,sha256=md3JO_ifs5j508p3TDNMgtQVtnQblpGEt_Wo4W56l8Y,107
99
- pycityagent-2.0.0a95.dist-info/entry_points.txt,sha256=BZcne49AAIFv-hawxGnPbblea7X3MtAtoPyDX8L4OC4,132
100
- pycityagent-2.0.0a95.dist-info/top_level.txt,sha256=yOmeu6cSXmiUtScu53a3s0p7BGtLMaV0aff83EHCTic,43
101
- pycityagent-2.0.0a95.dist-info/METADATA,sha256=WUcWf5gbldc2LyaR71a_QS8cZuGgUs9q0hrbXOdZ8_o,8657