pycityagent 2.0.0a96__cp311-cp311-macosx_11_0_arm64.whl → 2.0.0a98__cp311-cp311-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.
@@ -245,12 +245,12 @@ class Agent(ABC):
245
245
  config = json.load(f)
246
246
  return cls.import_block_config(config)
247
247
 
248
- def load_from_config(self, config: dict[str, list[dict]]) -> None:
248
+ def load_from_config(self, config: dict[str, Any]) -> None:
249
249
  """
250
250
  Update the current Agent instance's Block hierarchy using the provided configuration.
251
251
 
252
252
  - **Args**:
253
- - `config` (`dict[str, list[dict]]`): A dictionary containing the configuration for updating the agent and its blocks.
253
+ - `config` (`dict[str, Any]`): A dictionary containing the configuration for updating the agent and its blocks.
254
254
 
255
255
  - **Returns**:
256
256
  - `None`
@@ -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()
@@ -47,7 +47,7 @@ class AgentGroup:
47
47
  mlflow_run_id: str,
48
48
  embedding_model: Embeddings,
49
49
  logging_level: int,
50
- agent_config_file: Optional[dict[type[Agent], str]] = None,
50
+ agent_config_file: Optional[dict[type[Agent], Any]] = None,
51
51
  llm_semaphore: int = 200,
52
52
  environment: Optional[dict] = None,
53
53
  ):
@@ -76,7 +76,7 @@ class AgentGroup:
76
76
  - `mlflow_run_id` (str): Run identifier for MLflow tracking.
77
77
  - `embedding_model` (Embeddings): Model used for generating embeddings.
78
78
  - `logging_level` (int): Logging level for the agent group.
79
- - `agent_config_file` (Optional[Dict[Type[Agent], str]], optional): File paths for loading agent configurations. Defaults to None.
79
+ - `agent_config_file` (Optional[Dict[Type[Agent], Any]], optional): File paths for loading agent configurations. Defaults to None.
80
80
  - `environment` (Optional[Dict[str, str]], optional): Environment variables for the simulator. Defaults to None.
81
81
  """
82
82
  logger.setLevel(logging_level)
@@ -105,8 +105,6 @@ class AgentGroup:
105
105
  "status": self.avro_path / f"status.avro",
106
106
  "survey": self.avro_path / f"survey.avro",
107
107
  }
108
- if self.enable_pgsql:
109
- pass
110
108
  # Mlflow
111
109
  metric_config = config.prop_metric_request
112
110
  if metric_config is not None and metric_config.mlflow is not None:
@@ -147,7 +145,7 @@ class AgentGroup:
147
145
  # prepare Simulator
148
146
  logger.info(f"-----Initializing Simulator in AgentGroup {self._uuid} ...")
149
147
  self.simulator = Simulator(config)
150
- self.simulator.set_environment(environment)
148
+ self.simulator.set_environment(environment if environment else {})
151
149
  self.simulator.set_map(map_ref)
152
150
  self.projector = pyproj.Proj(
153
151
  ray.get(self.simulator.map.get_projector.remote()) # type:ignore
@@ -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.0a96
3
+ Version: 2.0.0a98
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
@@ -18,9 +18,9 @@ pycityagent/memory/utils.py,sha256=oJWLdPeJy_jcdKcDTo9JAH9kDZhqjoQhhv_zT9qWC0w,8
18
18
  pycityagent/memory/const.py,sha256=Wgsx0oztDrJDEpI9Dr6XeI6GXrABcP0UTOuEvMp1AD8,934
19
19
  pycityagent/memory/faiss_query.py,sha256=KPeyzIjD0dzkxr-TlOeCiIlkdh1WAyyipCAXUEt97Lk,17350
20
20
  pycityagent/memory/state.py,sha256=JFCBuK1AS-HqscvdGS9ATF9AUU8t29_2leDY_6iO2_4,5158
21
- pycityagent/simulation/simulation.py,sha256=GrD5VWaEvrKrBFwhEKUUfQfk2rweTEZnROaBZJXSni0,47134
21
+ pycityagent/simulation/simulation.py,sha256=YPRzB7wCL-K85W3hgvBWukefyEgZXZCi4egH6rZa6XA,47099
22
22
  pycityagent/simulation/__init__.py,sha256=u1WpgwVxPboXWMxrUQKMXJNmTKQYAeCaqZv9HmSxESY,118
23
- pycityagent/simulation/agentgroup.py,sha256=DYx68TckA5ox9x_GHID-3Gg19qABY-NR9QAO2BKKfMc,36814
23
+ pycityagent/simulation/agentgroup.py,sha256=lCz1Ruuz1TtuwzCnRVSPROey7FaXObiQmvNpv3lnzZw,36790
24
24
  pycityagent/simulation/storage/pg.py,sha256=xRshSOGttW-p0re0fNBOjOpb-nQ5msIE2LsdT79_E_Y,8425
25
25
  pycityagent/message/message_interceptor.py,sha256=Z7I1vqs4BrKadPAtQi-nfbkgboBAflXDSIcbIpDAxB8,17777
26
26
  pycityagent/message/__init__.py,sha256=f5QH7DKPqEAMyfSlBMnl3uouOKlsoel909STlIe7nUk,276
@@ -35,7 +35,7 @@ pycityagent/utils/parsers/__init__.py,sha256=AN2xgiPxszWK4rpX7zrqRsqNwfGF3WnCA5-
35
35
  pycityagent/utils/parsers/code_block_parser.py,sha256=jy6wHx9zypvJTWneCKuUaLQL19d4yLK6C_awc7y8A-k,1179
36
36
  pycityagent/utils/parsers/parser_base.py,sha256=ZbqRcqOBL9hfHVZSltQSQmJnWrtuJS9aYeOJU-FlJ0E,1725
37
37
  pycityagent/utils/parsers/json_parser.py,sha256=sakKohUuMcUH2toR85CAG_37D02ZoAn6LlzLgftUjmo,2923
38
- pycityagent/agent/agent_base.py,sha256=Fmp9wYwiDskEQxslweO3Jc-1OwbB9vgjv1VfZZIHSGI,39252
38
+ pycityagent/agent/agent_base.py,sha256=jYatA3gxdJTRRqvtcKBABD7NywwhlV18qUDnUiw8qRM,39238
39
39
  pycityagent/agent/__init__.py,sha256=U20yKu9QwSqAx_PHk5JwipfODkDfxONtumVfnsKjWFg,180
40
40
  pycityagent/agent/agent.py,sha256=zJs09Tzz53av59SzmrlJj6Yd-XId6voCYaxguLbbq3s,18991
41
41
  pycityagent/cli/wrapper.py,sha256=bAwmfWTXbGld-uiMnIMhKp22IVRQjhLUToknyUDk9rQ,1147
@@ -81,21 +81,21 @@ pycityagent/cityagent/societyagent.py,sha256=z1i7yPRz7Uupw5oGpMlFwyDi-8R4wHSCjgh
81
81
  pycityagent/cityagent/message_intercept.py,sha256=Am0u-hGFOBcvcNXE_WJos5iwh2QoJLihdSIz3sr_U9Y,4439
82
82
  pycityagent/cityagent/governmentagent.py,sha256=P3ufIfM5ldh2KC9y_y1ONowsV3FsFF5LWe0iQ3MVmgA,3067
83
83
  pycityagent/cityagent/blocks/dispatcher.py,sha256=gd3lyggvtkCq9Ou_icgua60H0UjHTzwHoynLl_iZoes,2939
84
- pycityagent/cityagent/blocks/needs_block.py,sha256=PDReR1GjF3qafR06Wfw_mizzBZ6xRQRq6KqgA9r8WOA,15321
84
+ pycityagent/cityagent/blocks/needs_block.py,sha256=1Mnr2vStBxSbmh2WByJdefOvTToKOENYDhyZFuL0KiM,15142
85
85
  pycityagent/cityagent/blocks/cognition_block.py,sha256=vy7wEvK72-sOieSSWidIXd5nKPLR-4f-ZYL7gyvje-0,15552
86
86
  pycityagent/cityagent/blocks/social_block.py,sha256=C1zMcN3RZBYewqw0MEYgtTf5Jzsol1Up3Ew9ovTSm1Y,15169
87
87
  pycityagent/cityagent/blocks/__init__.py,sha256=Tmy1CyQ8s3Iltp4xYWNg73Y28UWQv_LNWgMzgzquQT0,420
88
88
  pycityagent/cityagent/blocks/economy_block.py,sha256=w1rbTb4CqqXD9BDQuOAtCmrJ4KJjJYiQ5hJHEmCs6CA,20924
89
- pycityagent/cityagent/blocks/utils.py,sha256=YQkthaMkSCnT-1yfOkioGDvi2c-NLc5B-08BBlW4z0k,1781
89
+ pycityagent/cityagent/blocks/utils.py,sha256=dNIQGv7Br3hWOFznW1JRrFVeGw2vn3QRiPq732we5kQ,1792
90
90
  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
91
+ pycityagent/cityagent/blocks/plan_block.py,sha256=3TfXg6Iqa9Z_fh22KV2ZLNffNFglIV22vgCfGmorNe4,11710
92
+ pycityagent/cityagent/blocks/mobility_block.py,sha256=bUoExMdxlMzbnWHe1hx6bkR2Jjc1CZglux8RAXrWaRE,16876
93
93
  pycityagent/survey/models.py,sha256=g3xni4GcA1Py3vlGt6z4ltutjgQ4G0uINYAM8vKRJAw,5225
94
94
  pycityagent/survey/__init__.py,sha256=rxwou8U9KeFSP7rMzXtmtp2fVFZxK4Trzi-psx9LPIs,153
95
95
  pycityagent/survey/manager.py,sha256=QZEApC6tKe-g1waDa_O4Eg4CFkyL8KWa7tUGZnT_7WI,3397
96
- pycityagent-2.0.0a96.dist-info/RECORD,,
97
- pycityagent-2.0.0a96.dist-info/LICENSE,sha256=n2HPXiupinpyHMnIkbCf3OTYd3KMqbmldu1e7av0CAU,1084
98
- pycityagent-2.0.0a96.dist-info/WHEEL,sha256=NW1RskY9zow1Y68W-gXg0oZyBRAugI1JHywIzAIai5o,109
99
- pycityagent-2.0.0a96.dist-info/entry_points.txt,sha256=BZcne49AAIFv-hawxGnPbblea7X3MtAtoPyDX8L4OC4,132
100
- pycityagent-2.0.0a96.dist-info/top_level.txt,sha256=yOmeu6cSXmiUtScu53a3s0p7BGtLMaV0aff83EHCTic,43
101
- pycityagent-2.0.0a96.dist-info/METADATA,sha256=DAlWpG0FCdi2l-ae2kPICBXklMtezwsG1H_lFKHpi2E,8657
96
+ pycityagent-2.0.0a98.dist-info/RECORD,,
97
+ pycityagent-2.0.0a98.dist-info/LICENSE,sha256=n2HPXiupinpyHMnIkbCf3OTYd3KMqbmldu1e7av0CAU,1084
98
+ pycityagent-2.0.0a98.dist-info/WHEEL,sha256=NW1RskY9zow1Y68W-gXg0oZyBRAugI1JHywIzAIai5o,109
99
+ pycityagent-2.0.0a98.dist-info/entry_points.txt,sha256=BZcne49AAIFv-hawxGnPbblea7X3MtAtoPyDX8L4OC4,132
100
+ pycityagent-2.0.0a98.dist-info/top_level.txt,sha256=yOmeu6cSXmiUtScu53a3s0p7BGtLMaV0aff83EHCTic,43
101
+ pycityagent-2.0.0a98.dist-info/METADATA,sha256=n8hlDfjXb8yJTLVUOsIdUc2XpEYSc8yyO8lfJ3aL8XU,8657