pycityagent 2.0.0a85__cp311-cp311-macosx_11_0_arm64.whl → 2.0.0a87__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.
@@ -112,14 +112,6 @@ class ConsumptionBlock(Block):
112
112
  for i in range(len(firms_id)):
113
113
  demand_each_firm.append(int(consumption_each_firm[i]//prices[i]))
114
114
  real_consumption = await self.economy_client.calculate_consumption(firms_id, agent_id, demand_each_firm)
115
- if real_consumption == -1:
116
- node_id = await self.memory.stream.add_economy(description=f"I failed to buy goods, cause I do not have enough money.")
117
- return {
118
- 'success': False,
119
- 'evaluation': f"I failed to buy goods, cause I do not have enough money.",
120
- 'consumed_time': 0,
121
- 'node_id': node_id
122
- }
123
115
  node_id = await self.memory.stream.add_economy(description=f"I bought some goods, and spent {real_consumption:.1f} on {intention}")
124
116
  evaluation = {
125
117
  'success': True,
@@ -281,8 +273,8 @@ class MonthPlanBlock(Block):
281
273
  work_propensity = await self.memory.status.get('work_propensity')
282
274
  consumption_propensity = await self.memory.status.get('consumption_propensity')
283
275
  work_hours = work_propensity * self.num_labor_hours
284
- income = await self.economy_client.get(agent_id, 'income')
285
- income += work_hours * work_skill
276
+ # income = await self.economy_client.get(agent_id, 'income')
277
+ income = work_hours * work_skill
286
278
 
287
279
  wealth = await self.economy_client.get(agent_id, 'currency')
288
280
  wealth += work_hours * work_skill
@@ -348,7 +340,7 @@ class MonthPlanBlock(Block):
348
340
  except:
349
341
  self.llm_error += 1
350
342
 
351
- if self.UBI and self.forward_times >= 96 and self.forward_times % 12:
343
+ if self.UBI and self.forward_times >= 96 and self.forward_times % 12 == 0:
352
344
  obs_prompt = f'''
353
345
  {problem_prompt} {job_prompt} {consumption_prompt} {tax_prompt} {price_prompt}
354
346
  Your current savings account balance is ${wealth:.2f}. Interest rates, as set by your bank, stand at {interest_rate*100:.2f}%.
@@ -357,4 +349,5 @@ class MonthPlanBlock(Block):
357
349
  obs_prompt = prettify_document(obs_prompt)
358
350
  content = await self.llm.atext_request([{'role': 'user', 'content': obs_prompt}], timeout=300)
359
351
  await self.memory.status.update('ubi_opinion', [content], mode='merge')
360
-
352
+
353
+ self.forward_times += 1
@@ -343,5 +343,6 @@ def memory_config_nbs():
343
343
  "price": (float, float(np.mean(agent_skills))),
344
344
  "employees": (list, []),
345
345
  "employees_agent_id": (list, []),
346
+ "forward_times": (int, 0),
346
347
  }
347
348
  return EXTRA_ATTRIBUTES, {}, {}
@@ -1,5 +1,5 @@
1
1
  import pycityproto.city.economy.v2.economy_pb2 as economyv2
2
- from pycityagent.cityagent import SocietyAgent
2
+ from pycityagent.cityagent import SocietyAgent, NBSAgent
3
3
 
4
4
  async def mobility_metric(simulation):
5
5
  # 使用函数属性来存储计数
@@ -22,20 +22,31 @@ async def mobility_metric(simulation):
22
22
  async def economy_metric(simulation):
23
23
  # 使用函数属性来存储计数
24
24
  if not hasattr(economy_metric, 'step_count'):
25
- economy_metric.step_count = 0
25
+ economy_metric.nbs_id = None
26
+ economy_metric.nbs_uuid = None
27
+
28
+ if economy_metric.nbs_id is None:
29
+ nbs_id = await simulation.economy_client.get_org_entity_ids(economyv2.ORG_TYPE_NBS)
30
+ nbs_id = nbs_id[0]
31
+ economy_metric.nbs_id = nbs_id
32
+ nbs_uuids = await simulation.filter(types=[NBSAgent])
33
+ economy_metric.nbs_uuid = nbs_uuids[0]
26
34
 
27
- nbs_id = await simulation.economy_client.get_org_entity_ids(economyv2.ORG_TYPE_NBS)
28
- nbs_id = nbs_id[0]
29
35
  try:
30
36
  real_gdp = await simulation.economy_client.get(nbs_id, 'real_gdp')
31
37
  except:
32
38
  real_gdp = []
33
39
  if len(real_gdp) > 0:
34
40
  real_gdp = real_gdp[0]
35
- await simulation.mlflow_client.log_metric(key="real_gdp", value=real_gdp, step=economy_metric.step_count)
41
+ forward_times_info = await simulation.gather("forward_times", [economy_metric.nbs_uuid])
42
+ step_count = 0
43
+ for group_gather in forward_times_info:
44
+ for agent_uuid, forward_times in group_gather.items():
45
+ if agent_uuid == economy_metric.nbs_uuid:
46
+ step_count = forward_times
47
+ await simulation.mlflow_client.log_metric(key="real_gdp", value=real_gdp, step=step_count)
36
48
  other_metrics = ['prices', 'working_hours', 'depression', 'consumption_currency', 'income_currency']
37
49
  other_metrics_names = ['price', 'working_hours', 'depression', 'consumption', 'income']
38
50
  for metric, metric_name in zip(other_metrics, other_metrics_names):
39
51
  metric_value = (await simulation.economy_client.get(nbs_id, metric))[-1]
40
- await simulation.mlflow_client.log_metric(key=metric_name, value=metric_value, step=economy_metric.step_count)
41
- economy_metric.step_count += 1
52
+ await simulation.mlflow_client.log_metric(key=metric_name, value=metric_value, step=step_count)
@@ -115,4 +115,6 @@ class NBSAgent(InstitutionAgent):
115
115
  await self.economy_client.update(
116
116
  self._agent_id, "income_currency", [income_currency], mode="merge"
117
117
  )
118
- print("nbs forward end")
118
+ print("nbs forward end")
119
+ self.forward_times += 1
120
+ await self.memory.status.update("forward_times", self.forward_times)
@@ -128,7 +128,8 @@ class Simulator:
128
128
  min_step_time=config["simulator"].get("min_step_time", 1000),
129
129
  sim_addr=config["simulator"].get("server", None),
130
130
  )
131
- self.server_addr = sim_env.sim_addr
131
+ primary_node_ip = config["simulator"].get("ad", "http://localhost")
132
+ self.server_addr = primary_node_ip.rstrip("/")+f":{sim_env.sim_port}"
132
133
  config["simulator"]["server"] = self.server_addr
133
134
  config["simulator"]["_server_activated"] = True
134
135
  # using local client
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pycityagent
3
- Version: 2.0.0a85
3
+ Version: 2.0.0a87
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,9 +1,3 @@
1
- pycityagent-2.0.0a85.dist-info/RECORD,,
2
- pycityagent-2.0.0a85.dist-info/LICENSE,sha256=n2HPXiupinpyHMnIkbCf3OTYd3KMqbmldu1e7av0CAU,1084
3
- pycityagent-2.0.0a85.dist-info/WHEEL,sha256=NW1RskY9zow1Y68W-gXg0oZyBRAugI1JHywIzAIai5o,109
4
- pycityagent-2.0.0a85.dist-info/entry_points.txt,sha256=BZcne49AAIFv-hawxGnPbblea7X3MtAtoPyDX8L4OC4,132
5
- pycityagent-2.0.0a85.dist-info/top_level.txt,sha256=yOmeu6cSXmiUtScu53a3s0p7BGtLMaV0aff83EHCTic,43
6
- pycityagent-2.0.0a85.dist-info/METADATA,sha256=KKmALYa8DummI6EtxRIqeGaH5Fg_lS4yElcWAOdV2wU,9110
7
1
  pycityagent/pycityagent-sim,sha256=Ax6cjHjT8VcT5t07VboL_Ruor2eXSdSEml4Jvv-L5dQ,36972594
8
2
  pycityagent/__init__.py,sha256=PUKWTXc-xdMG7px8oTNclodsILUgypANj2Z647sY63k,808
9
3
  pycityagent/pycityagent-ui,sha256=Ur95yZygIaZ5l_CDqP9394M5GQ66iV5PkcNPYFWqzvk,41225346
@@ -52,7 +46,7 @@ pycityagent/workflow/prompt.py,sha256=rzenP4EFGxbWE1aq-x2036b6umKvi5cQx2xtWULwgI
52
46
  pycityagent/workflow/block.py,sha256=WJfCeL8e117GzkVPJCRNsQZZinccMnVyEubkwrf-17U,12295
53
47
  pycityagent/workflow/trigger.py,sha256=4nzAwywGQsFabgo6gzp-vD2EV4wII7Z0LHGEAsflSEY,7608
54
48
  pycityagent/environment/__init__.py,sha256=fFIth2jxxgZ92cXm-aoM2igHgaSqsYGwtBhyb7opjzk,166
55
- pycityagent/environment/simulator.py,sha256=sbM0FMjR_q2mssbpMI7Lx9QI2iFj1Hbzg48fbRMd4tY,23206
49
+ pycityagent/environment/simulator.py,sha256=ubOsoeyo81LZKfOSeS4eGrpn-7lC-hrdCBbcLH9NbK8,23324
56
50
  pycityagent/environment/utils/port.py,sha256=3OM6kSUt3PxvDUOlgyiendBtETaWU8Mzk_8H0TzTmYg,295
57
51
  pycityagent/environment/utils/grpc.py,sha256=_lB4-k4dTKuNvApaDiYgFxiLTPtYG42DVQtG9yOj9pQ,2022
58
52
  pycityagent/environment/utils/base64.py,sha256=hoREzQo3FXMN79pqQLO2jgsDEvudciomyKii7MWljAM,374
@@ -72,12 +66,12 @@ pycityagent/environment/sim/social_service.py,sha256=Y4A56aKXsjSv18UFumGPjQoJVMc
72
66
  pycityagent/environment/sim/light_service.py,sha256=q4pKcGrm7WU0h29I1dFIDOz2OV0BM-2s37uC6zokkoA,4290
73
67
  pycityagent/environment/sim/clock_service.py,sha256=4Hly8CToghj0x_XbDgGrIZy1YYAlDH0EUGCiCDYpk_I,1375
74
68
  pycityagent/environment/sim/road_service.py,sha256=Bb1sreO0Knt9tcqH_WJF-I3P3G92bRAlzDBEa--25GE,1297
75
- pycityagent/cityagent/metrics.py,sha256=yXZ4uRXARjDAvPKyquut7YWs363nDcIV0J1KQgYacZE,2169
76
- pycityagent/cityagent/memory_config.py,sha256=T21XdQ-um16LMMirLO2W14LcbJp3afnYF-AsUZKfxWM,11923
69
+ pycityagent/cityagent/metrics.py,sha256=SdCxEuO-wgsPGo3H6xywnOAfP5Lre-bc7HNAQ-n53mA,2687
70
+ pycityagent/cityagent/memory_config.py,sha256=lCySjh8jpE3Sj-_XTCPizxJN8rjfcYD54sed7wi2EDw,11958
77
71
  pycityagent/cityagent/bankagent.py,sha256=I6MNG1fUbxKyWCLxCtvOjeVahong_LhHQKmJdRPhQL8,4097
78
72
  pycityagent/cityagent/__init__.py,sha256=gcBQ-a50XegFtjigQ7xDXRBZrywBKqifiQFSRnEF8gM,572
79
73
  pycityagent/cityagent/firmagent.py,sha256=vZr7kdjnxcCZ5qX7hmUIYuQQWd44GcRPbdi76WGSFy4,3760
80
- pycityagent/cityagent/nbsagent.py,sha256=knSaQbCNkWi7bZjwwEr_hTKj44_q67eHif6HI3W9i1M,4558
74
+ pycityagent/cityagent/nbsagent.py,sha256=rrzL-Ep-gWB8kvoPA8nBokY1zoEZGpyQjP9oy7ZuVL4,4676
81
75
  pycityagent/cityagent/initial.py,sha256=0DSOWnVVknMw6xoJWfdZUFBH3yti8y800wnkXXCocxY,6194
82
76
  pycityagent/cityagent/societyagent.py,sha256=1c6k3RgxQ7AAYCiBXwiSZLDkCDMgCrBzNF6vi6lK2Yc,20069
83
77
  pycityagent/cityagent/message_intercept.py,sha256=dyT1G-nMxKb2prhgtyFFHFz593qBrkk5DnHsHvG1OIc,4418
@@ -87,7 +81,7 @@ pycityagent/cityagent/blocks/needs_block.py,sha256=NYKrGDoYCuXoupMNMuSNhx4Ci1paC
87
81
  pycityagent/cityagent/blocks/cognition_block.py,sha256=yzjB0D_95vytpa5xiVdmTSpGp8H9HXcjWzzFN0OpP0k,15398
88
82
  pycityagent/cityagent/blocks/social_block.py,sha256=eedOlwRTGI47QFELYmfe2a_aj0GuHJweSyDxA6AYXcU,15493
89
83
  pycityagent/cityagent/blocks/__init__.py,sha256=h6si6WBcVVuglIskKQKA8Cxtf_VKen1sNPqOFKI311Q,420
90
- pycityagent/cityagent/blocks/economy_block.py,sha256=SSqb2qX5cVQ1zM8hyxvhnyTwgGwUrV2YViKtGRXmJhQ,20079
84
+ pycityagent/cityagent/blocks/economy_block.py,sha256=ZhNzhkXxzFidQQRLS5jNv5msHSdoASouKBqvAzecJU4,19709
91
85
  pycityagent/cityagent/blocks/utils.py,sha256=K--6odjUDUu9YrwrHPaiPIHryo7m_MBmcBqDAy3cV5M,1816
92
86
  pycityagent/cityagent/blocks/other_block.py,sha256=LdtL6248xvMvvRQx6NvdlJrWWZFu8Xusjxb9yEh1M0k,4365
93
87
  pycityagent/cityagent/blocks/plan_block.py,sha256=A5DvtXIy98MZkRGUQmp26grNI5i0BVbl3aEM_Ebd6Z4,11271
@@ -95,3 +89,9 @@ pycityagent/cityagent/blocks/mobility_block.py,sha256=qkRiV0nkGOUUoo9lGIjAFE_Hl0
95
89
  pycityagent/survey/models.py,sha256=g3xni4GcA1Py3vlGt6z4ltutjgQ4G0uINYAM8vKRJAw,5225
96
90
  pycityagent/survey/__init__.py,sha256=rxwou8U9KeFSP7rMzXtmtp2fVFZxK4Trzi-psx9LPIs,153
97
91
  pycityagent/survey/manager.py,sha256=tHkdeq4lTfAHwvgf4-udsXri0z2l6E00rEbvwl7SqRs,3439
92
+ pycityagent-2.0.0a87.dist-info/RECORD,,
93
+ pycityagent-2.0.0a87.dist-info/LICENSE,sha256=n2HPXiupinpyHMnIkbCf3OTYd3KMqbmldu1e7av0CAU,1084
94
+ pycityagent-2.0.0a87.dist-info/WHEEL,sha256=NW1RskY9zow1Y68W-gXg0oZyBRAugI1JHywIzAIai5o,109
95
+ pycityagent-2.0.0a87.dist-info/entry_points.txt,sha256=BZcne49AAIFv-hawxGnPbblea7X3MtAtoPyDX8L4OC4,132
96
+ pycityagent-2.0.0a87.dist-info/top_level.txt,sha256=yOmeu6cSXmiUtScu53a3s0p7BGtLMaV0aff83EHCTic,43
97
+ pycityagent-2.0.0a87.dist-info/METADATA,sha256=nhB__BcNLDfb1PCA7Wjb5GWYo7mRegc1KPQFypOERlk,9110