pycityagent 2.0.0a85__cp311-cp311-macosx_11_0_arm64.whl → 2.0.0a88__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,
@@ -175,16 +167,19 @@ class MonthPlanBlock(Block):
175
167
  "UBI",
176
168
  "num_labor_hours",
177
169
  "productivity_per_labor",
170
+ "time_diff"
178
171
  ]
179
172
  default_values = {
180
173
  "UBI": 0,
181
174
  "num_labor_hours": 168,
182
175
  "productivity_per_labor": 1,
176
+ "time_diff": 30 * 24 * 60 * 60
183
177
  }
184
178
  fields_description = {
185
179
  "UBI": "Universal Basic Income",
186
180
  "num_labor_hours": "Number of labor hours per month",
187
181
  "productivity_per_labor": "Productivity per labor hour",
182
+ "time_diff": "Time difference between two triggers"
188
183
  }
189
184
 
190
185
  def __init__(self, llm: LLM, memory: Memory, simulator: Simulator, economy_client: EconomyClient):
@@ -192,14 +187,13 @@ class MonthPlanBlock(Block):
192
187
  self.economy_client = economy_client
193
188
  self.llm_error = 0
194
189
  self.last_time_trigger = None
195
- self.time_diff = 30 * 24 * 60 * 60
196
190
  self.forward_times = 0
197
191
 
198
192
  # configurable fields
199
193
  self.UBI = 0
200
194
  self.num_labor_hours = 168
201
195
  self.productivity_per_labor = 1
202
-
196
+ self.time_diff = 30 * 24 * 60 * 60
203
197
 
204
198
  async def month_trigger(self):
205
199
  now_time = await self.simulator.get_time()
@@ -262,11 +256,11 @@ class MonthPlanBlock(Block):
262
256
  Any other output words are NOT allowed.
263
257
  '''
264
258
  obs_prompt = prettify_document(obs_prompt)
265
- await self.memory.status.update('dialog_queue', [{'role': 'user', 'content': obs_prompt}], mode='merge')
266
- dialog_queue = await self.memory.status.get('dialog_queue')
267
- content = await self.llm.atext_request(list(dialog_queue), timeout=300)
268
- await self.memory.status.update('dialog_queue', [{'role': 'assistant', 'content': content}], mode='merge')
269
259
  try:
260
+ await self.memory.status.update('dialog_queue', [{'role': 'user', 'content': obs_prompt}], mode='merge')
261
+ dialog_queue = await self.memory.status.get('dialog_queue')
262
+ content = await self.llm.atext_request(list(dialog_queue), timeout=300)
263
+ await self.memory.status.update('dialog_queue', [{'role': 'assistant', 'content': content}], mode='merge')
270
264
  propensity_dict = extract_dict_from_string(content)[0]
271
265
  work_propensity, consumption_propensity = propensity_dict['work'], propensity_dict['consumption']
272
266
  if isinstance(work_propensity, numbers.Number) and isinstance(consumption_propensity, numbers.Number):
@@ -281,8 +275,8 @@ class MonthPlanBlock(Block):
281
275
  work_propensity = await self.memory.status.get('work_propensity')
282
276
  consumption_propensity = await self.memory.status.get('consumption_propensity')
283
277
  work_hours = work_propensity * self.num_labor_hours
284
- income = await self.economy_client.get(agent_id, 'income')
285
- income += work_hours * work_skill
278
+ # income = await self.economy_client.get(agent_id, 'income')
279
+ income = work_hours * work_skill
286
280
 
287
281
  wealth = await self.economy_client.get(agent_id, 'currency')
288
282
  wealth += work_hours * work_skill
@@ -348,7 +342,7 @@ class MonthPlanBlock(Block):
348
342
  except:
349
343
  self.llm_error += 1
350
344
 
351
- if self.UBI and self.forward_times >= 96 and self.forward_times % 12:
345
+ if self.UBI and self.forward_times >= 96 and self.forward_times % 12 == 0:
352
346
  obs_prompt = f'''
353
347
  {problem_prompt} {job_prompt} {consumption_prompt} {tax_prompt} {price_prompt}
354
348
  Your current savings account balance is ${wealth:.2f}. Interest rates, as set by your bank, stand at {interest_rate*100:.2f}%.
@@ -357,4 +351,5 @@ class MonthPlanBlock(Block):
357
351
  obs_prompt = prettify_document(obs_prompt)
358
352
  content = await self.llm.atext_request([{'role': 'user', 'content': obs_prompt}], timeout=300)
359
353
  await self.memory.status.update('ubi_opinion', [content], mode='merge')
360
-
354
+
355
+ 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
pycityagent/llm/llm.py CHANGED
@@ -203,7 +203,7 @@ class LLM:
203
203
  frequency_penalty: Optional[float] = None,
204
204
  presence_penalty: Optional[float] = None,
205
205
  timeout: int = 300,
206
- retries=3,
206
+ retries=10,
207
207
  tools: Optional[list[dict[str, Any]]] = None,
208
208
  tool_choice: Optional[dict[str, Any]] = None,
209
209
  ):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pycityagent
3
- Version: 2.0.0a85
3
+ Version: 2.0.0a88
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,9 @@
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
1
+ pycityagent-2.0.0a88.dist-info/RECORD,,
2
+ pycityagent-2.0.0a88.dist-info/LICENSE,sha256=n2HPXiupinpyHMnIkbCf3OTYd3KMqbmldu1e7av0CAU,1084
3
+ pycityagent-2.0.0a88.dist-info/WHEEL,sha256=NW1RskY9zow1Y68W-gXg0oZyBRAugI1JHywIzAIai5o,109
4
+ pycityagent-2.0.0a88.dist-info/entry_points.txt,sha256=BZcne49AAIFv-hawxGnPbblea7X3MtAtoPyDX8L4OC4,132
5
+ pycityagent-2.0.0a88.dist-info/top_level.txt,sha256=yOmeu6cSXmiUtScu53a3s0p7BGtLMaV0aff83EHCTic,43
6
+ pycityagent-2.0.0a88.dist-info/METADATA,sha256=RX-Ot6Yyl_W0-bl9cJur9nQVLlAoI3WQ2YKiz37qTwk,9110
7
7
  pycityagent/pycityagent-sim,sha256=Ax6cjHjT8VcT5t07VboL_Ruor2eXSdSEml4Jvv-L5dQ,36972594
8
8
  pycityagent/__init__.py,sha256=PUKWTXc-xdMG7px8oTNclodsILUgypANj2Z647sY63k,808
9
9
  pycityagent/pycityagent-ui,sha256=Ur95yZygIaZ5l_CDqP9394M5GQ66iV5PkcNPYFWqzvk,41225346
@@ -15,7 +15,7 @@ pycityagent/tools/__init__.py,sha256=y7sMVMHf0AbivlczM2h-kr7mkgXK-WAx3S9BXLXkWvw
15
15
  pycityagent/tools/tool.py,sha256=4ZJSHbNM8dfAVwZEw8T0a2_9OuPsPQpKSVL4WxZVBUc,9022
16
16
  pycityagent/llm/llmconfig.py,sha256=6AqCMV4B_JqBD2mb98bLGzpUdlOCnziQKae-Hhxxp-E,469
17
17
  pycityagent/llm/__init__.py,sha256=iWs6FLgrbRVIiqOf4ILS89gkVCTvS7HFC3vG-MWuyko,205
18
- pycityagent/llm/llm.py,sha256=A1Q-dKEXHJKhBnElI7Ci6eIK-A7I-UZNQxC_hEgEa-4,20018
18
+ pycityagent/llm/llm.py,sha256=vMw9AVftrsmbGkhRIwJ7jftFWpzTofhfQmu7TazDCaQ,20019
19
19
  pycityagent/llm/embeddings.py,sha256=3610I-_scAy8HwRNpT8hVJpH9_8_pTLCPptqnzSq10o,11322
20
20
  pycityagent/llm/utils.py,sha256=rSx_fp-_Gh0vZ-x2rqAUqnpS56BVTZ4ChfAMarB8S1A,195
21
21
  pycityagent/memory/memory.py,sha256=5mUweo-BgQYbXmVRAk7HTUXsar6O6iYz79VbLuMAvjo,45063
@@ -52,7 +52,7 @@ pycityagent/workflow/prompt.py,sha256=rzenP4EFGxbWE1aq-x2036b6umKvi5cQx2xtWULwgI
52
52
  pycityagent/workflow/block.py,sha256=WJfCeL8e117GzkVPJCRNsQZZinccMnVyEubkwrf-17U,12295
53
53
  pycityagent/workflow/trigger.py,sha256=4nzAwywGQsFabgo6gzp-vD2EV4wII7Z0LHGEAsflSEY,7608
54
54
  pycityagent/environment/__init__.py,sha256=fFIth2jxxgZ92cXm-aoM2igHgaSqsYGwtBhyb7opjzk,166
55
- pycityagent/environment/simulator.py,sha256=sbM0FMjR_q2mssbpMI7Lx9QI2iFj1Hbzg48fbRMd4tY,23206
55
+ pycityagent/environment/simulator.py,sha256=ubOsoeyo81LZKfOSeS4eGrpn-7lC-hrdCBbcLH9NbK8,23324
56
56
  pycityagent/environment/utils/port.py,sha256=3OM6kSUt3PxvDUOlgyiendBtETaWU8Mzk_8H0TzTmYg,295
57
57
  pycityagent/environment/utils/grpc.py,sha256=_lB4-k4dTKuNvApaDiYgFxiLTPtYG42DVQtG9yOj9pQ,2022
58
58
  pycityagent/environment/utils/base64.py,sha256=hoREzQo3FXMN79pqQLO2jgsDEvudciomyKii7MWljAM,374
@@ -72,12 +72,12 @@ pycityagent/environment/sim/social_service.py,sha256=Y4A56aKXsjSv18UFumGPjQoJVMc
72
72
  pycityagent/environment/sim/light_service.py,sha256=q4pKcGrm7WU0h29I1dFIDOz2OV0BM-2s37uC6zokkoA,4290
73
73
  pycityagent/environment/sim/clock_service.py,sha256=4Hly8CToghj0x_XbDgGrIZy1YYAlDH0EUGCiCDYpk_I,1375
74
74
  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
75
+ pycityagent/cityagent/metrics.py,sha256=SdCxEuO-wgsPGo3H6xywnOAfP5Lre-bc7HNAQ-n53mA,2687
76
+ pycityagent/cityagent/memory_config.py,sha256=lCySjh8jpE3Sj-_XTCPizxJN8rjfcYD54sed7wi2EDw,11958
77
77
  pycityagent/cityagent/bankagent.py,sha256=I6MNG1fUbxKyWCLxCtvOjeVahong_LhHQKmJdRPhQL8,4097
78
78
  pycityagent/cityagent/__init__.py,sha256=gcBQ-a50XegFtjigQ7xDXRBZrywBKqifiQFSRnEF8gM,572
79
79
  pycityagent/cityagent/firmagent.py,sha256=vZr7kdjnxcCZ5qX7hmUIYuQQWd44GcRPbdi76WGSFy4,3760
80
- pycityagent/cityagent/nbsagent.py,sha256=knSaQbCNkWi7bZjwwEr_hTKj44_q67eHif6HI3W9i1M,4558
80
+ pycityagent/cityagent/nbsagent.py,sha256=rrzL-Ep-gWB8kvoPA8nBokY1zoEZGpyQjP9oy7ZuVL4,4676
81
81
  pycityagent/cityagent/initial.py,sha256=0DSOWnVVknMw6xoJWfdZUFBH3yti8y800wnkXXCocxY,6194
82
82
  pycityagent/cityagent/societyagent.py,sha256=1c6k3RgxQ7AAYCiBXwiSZLDkCDMgCrBzNF6vi6lK2Yc,20069
83
83
  pycityagent/cityagent/message_intercept.py,sha256=dyT1G-nMxKb2prhgtyFFHFz593qBrkk5DnHsHvG1OIc,4418
@@ -87,7 +87,7 @@ pycityagent/cityagent/blocks/needs_block.py,sha256=NYKrGDoYCuXoupMNMuSNhx4Ci1paC
87
87
  pycityagent/cityagent/blocks/cognition_block.py,sha256=yzjB0D_95vytpa5xiVdmTSpGp8H9HXcjWzzFN0OpP0k,15398
88
88
  pycityagent/cityagent/blocks/social_block.py,sha256=eedOlwRTGI47QFELYmfe2a_aj0GuHJweSyDxA6AYXcU,15493
89
89
  pycityagent/cityagent/blocks/__init__.py,sha256=h6si6WBcVVuglIskKQKA8Cxtf_VKen1sNPqOFKI311Q,420
90
- pycityagent/cityagent/blocks/economy_block.py,sha256=SSqb2qX5cVQ1zM8hyxvhnyTwgGwUrV2YViKtGRXmJhQ,20079
90
+ pycityagent/cityagent/blocks/economy_block.py,sha256=l47x2Iq15Rjj9WsH3p398dtpcejat4aCkC3X160xBlE,19843
91
91
  pycityagent/cityagent/blocks/utils.py,sha256=K--6odjUDUu9YrwrHPaiPIHryo7m_MBmcBqDAy3cV5M,1816
92
92
  pycityagent/cityagent/blocks/other_block.py,sha256=LdtL6248xvMvvRQx6NvdlJrWWZFu8Xusjxb9yEh1M0k,4365
93
93
  pycityagent/cityagent/blocks/plan_block.py,sha256=A5DvtXIy98MZkRGUQmp26grNI5i0BVbl3aEM_Ebd6Z4,11271