pycityagent 2.0.0a10__tar.gz → 2.0.0a11__tar.gz
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.
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/PKG-INFO +1 -1
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/agent.py +48 -84
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/simulator.py +1 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/simulation/agentgroup.py +2 -2
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pyproject.toml +1 -1
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/README.md +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/economy/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/economy/econ_client.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/interact/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/interact/interact.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/message/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/sence/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/sence/static.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/sidecar/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/sidecar/sidecarv2.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/sim/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/sim/aoi_service.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/sim/client.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/sim/clock_service.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/sim/economy_services.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/sim/lane_service.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/sim/light_service.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/sim/person_service.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/sim/road_service.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/sim/sim_env.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/sim/social_service.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/utils/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/utils/base64.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/utils/const.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/utils/geojson.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/utils/grpc.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/utils/map_utils.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/utils/port.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/utils/protobuf.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/llm/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/llm/embedding.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/llm/llm.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/llm/llmconfig.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/llm/utils.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/memory/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/memory/const.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/memory/memory.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/memory/memory_base.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/memory/profile.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/memory/self_define.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/memory/state.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/memory/utils.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/message/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/message/messager.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/simulation/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/simulation/interview.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/simulation/simulation.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/simulation/survey/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/simulation/survey/manager.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/simulation/survey/models.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/simulation/ui/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/simulation/ui/interface.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/utils/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/utils/decorators.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/utils/parsers/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/utils/parsers/code_block_parser.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/utils/parsers/json_parser.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/utils/parsers/parser_base.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/workflow/__init__.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/workflow/block.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/workflow/prompt.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/workflow/tool.py +0 -0
- {pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/workflow/trigger.py +0 -0
@@ -8,6 +8,7 @@ from datetime import datetime
|
|
8
8
|
from enum import Enum
|
9
9
|
import logging
|
10
10
|
import random
|
11
|
+
import uuid
|
11
12
|
from typing import Dict, List, Optional
|
12
13
|
|
13
14
|
from pycityagent.environment.sim.person_service import PersonService
|
@@ -64,6 +65,7 @@ class Agent(ABC):
|
|
64
65
|
"""
|
65
66
|
self._name = name
|
66
67
|
self._type = type
|
68
|
+
self._uuid = uuid.uuid4()
|
67
69
|
self._llm_client = llm_client
|
68
70
|
self._economy_client = economy_client
|
69
71
|
self._messager = messager
|
@@ -118,77 +120,6 @@ class Agent(ABC):
|
|
118
120
|
"""
|
119
121
|
self._exp_id = exp_id
|
120
122
|
|
121
|
-
async def _bind_to_simulator(self):
|
122
|
-
"""
|
123
|
-
Bind Agent to Simulator
|
124
|
-
|
125
|
-
Args:
|
126
|
-
person_template (dict, optional): The person template in dict format. Defaults to PersonService.default_dict_person().
|
127
|
-
"""
|
128
|
-
if self._simulator is None:
|
129
|
-
logging.warning("Simulator is not set")
|
130
|
-
return
|
131
|
-
if not self._has_bound_to_simulator:
|
132
|
-
FROM_MEMORY_KEYS = {
|
133
|
-
"attribute",
|
134
|
-
"home",
|
135
|
-
"work",
|
136
|
-
"vehicle_attribute",
|
137
|
-
"bus_attribute",
|
138
|
-
"pedestrian_attribute",
|
139
|
-
"bike_attribute",
|
140
|
-
}
|
141
|
-
simulator = self._simulator
|
142
|
-
memory = self.memory
|
143
|
-
person_id = await memory.get("id")
|
144
|
-
# ATTENTION:模拟器分配的id从0开始
|
145
|
-
if person_id >= 0:
|
146
|
-
await simulator.get_person(person_id)
|
147
|
-
logging.debug(f"Binding to Person `{person_id}` already in Simulator")
|
148
|
-
else:
|
149
|
-
dict_person = deepcopy(self._person_template)
|
150
|
-
for _key in FROM_MEMORY_KEYS:
|
151
|
-
try:
|
152
|
-
_value = await memory.get(_key)
|
153
|
-
if _value:
|
154
|
-
dict_person[_key] = _value
|
155
|
-
except KeyError as e:
|
156
|
-
continue
|
157
|
-
resp = await simulator.add_person(
|
158
|
-
dict2pb(dict_person, person_pb2.Person())
|
159
|
-
)
|
160
|
-
person_id = resp["person_id"]
|
161
|
-
await memory.update("id", person_id, protect_llm_read_only_fields=False)
|
162
|
-
logging.debug(
|
163
|
-
f"Binding to Person `{person_id}` just added to Simulator"
|
164
|
-
)
|
165
|
-
# 防止模拟器还没有到prepare阶段导致get_person出错
|
166
|
-
self._has_bound_to_simulator = True
|
167
|
-
self._agent_id = person_id
|
168
|
-
|
169
|
-
async def _bind_to_economy(self):
|
170
|
-
if self._economy_client is None:
|
171
|
-
logging.warning("Economy client is not set")
|
172
|
-
return
|
173
|
-
if not self._has_bound_to_economy:
|
174
|
-
if self._has_bound_to_simulator:
|
175
|
-
try:
|
176
|
-
await self._economy_client.remove_agents([self._agent_id])
|
177
|
-
except:
|
178
|
-
pass
|
179
|
-
person_id = await self.memory.get("id")
|
180
|
-
await self._economy_client.add_agents(
|
181
|
-
{
|
182
|
-
"id": person_id,
|
183
|
-
"currency": await self.memory.get("currency"),
|
184
|
-
}
|
185
|
-
)
|
186
|
-
self._has_bound_to_economy = True
|
187
|
-
else:
|
188
|
-
logging.debug(
|
189
|
-
f"Binding to Economy before binding to Simulator, skip binding to Economy Simulator"
|
190
|
-
)
|
191
|
-
|
192
123
|
@property
|
193
124
|
def llm(self):
|
194
125
|
"""The Agent's LLM"""
|
@@ -455,28 +386,60 @@ class InstitutionAgent(Agent):
|
|
455
386
|
self._agent_id = _id
|
456
387
|
await self._memory.update("id", _id, protect_llm_read_only_fields=False)
|
457
388
|
try:
|
458
|
-
await self._economy_client.
|
389
|
+
await self._economy_client.remove_orgs([self._agent_id])
|
459
390
|
except:
|
460
391
|
pass
|
461
392
|
try:
|
462
393
|
id = await self._memory.get("id")
|
463
394
|
type = await self._memory.get("type")
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
395
|
+
try:
|
396
|
+
nominal_gdp = await self._memory.get("nominal_gdp")
|
397
|
+
except:
|
398
|
+
nominal_gdp = []
|
399
|
+
try:
|
400
|
+
real_gdp = await self._memory.get("real_gdp")
|
401
|
+
except:
|
402
|
+
real_gdp = []
|
403
|
+
try:
|
404
|
+
unemployment = await self._memory.get("unemployment")
|
405
|
+
except:
|
406
|
+
unemployment = []
|
407
|
+
try:
|
408
|
+
wages = await self._memory.get("wages")
|
409
|
+
except:
|
410
|
+
wages = []
|
411
|
+
try:
|
412
|
+
prices = await self._memory.get("prices")
|
413
|
+
except:
|
414
|
+
prices = []
|
415
|
+
try:
|
416
|
+
inventory = await self._memory.get("inventory")
|
417
|
+
except:
|
418
|
+
inventory = 0
|
419
|
+
try:
|
420
|
+
price = await self._memory.get("price")
|
421
|
+
except:
|
422
|
+
price = 0
|
423
|
+
try:
|
424
|
+
currency = await self._memory.get("currency")
|
425
|
+
except:
|
426
|
+
currency = 0.0
|
427
|
+
try:
|
428
|
+
interest_rate = await self._memory.get("interest_rate")
|
429
|
+
except:
|
430
|
+
interest_rate = 0.0
|
431
|
+
try:
|
432
|
+
bracket_cutoffs = await self._memory.get("bracket_cutoffs")
|
433
|
+
except:
|
434
|
+
bracket_cutoffs = []
|
435
|
+
try:
|
436
|
+
bracket_rates = await self._memory.get("bracket_rates")
|
437
|
+
except:
|
438
|
+
bracket_rates = []
|
475
439
|
await self._economy_client.add_orgs(
|
476
440
|
{
|
477
441
|
"id": id,
|
478
442
|
"type": type,
|
479
|
-
"currency": currency,
|
480
443
|
"nominal_gdp": nominal_gdp,
|
481
444
|
"real_gdp": real_gdp,
|
482
445
|
"unemployment": unemployment,
|
@@ -484,6 +447,7 @@ class InstitutionAgent(Agent):
|
|
484
447
|
"prices": prices,
|
485
448
|
"inventory": inventory,
|
486
449
|
"price": price,
|
450
|
+
"currency": currency,
|
487
451
|
"interest_rate": interest_rate,
|
488
452
|
"bracket_cutoffs": bracket_cutoffs,
|
489
453
|
"bracket_rates": bracket_rates,
|
@@ -125,13 +125,13 @@ class AgentGroup:
|
|
125
125
|
try:
|
126
126
|
# 获取开始时间
|
127
127
|
start_time = await self.simulator.get_time()
|
128
|
-
|
128
|
+
start_time = int(start_time)
|
129
129
|
# 计算结束时间(秒)
|
130
130
|
end_time = start_time + day * 24 * 3600 # 将天数转换为秒
|
131
131
|
|
132
132
|
while True:
|
133
133
|
current_time = await self.simulator.get_time()
|
134
|
-
|
134
|
+
current_time = int(current_time)
|
135
135
|
if current_time >= end_time:
|
136
136
|
break
|
137
137
|
await self.step()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/environment/sim/economy_services.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{pycityagent-2.0.0a10 → pycityagent-2.0.0a11}/pycityagent/utils/parsers/code_block_parser.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|