pycityagent 2.0.0a21__py3-none-any.whl → 2.0.0a22__py3-none-any.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.
- pycityagent/agent.py +6 -3
- pycityagent/environment/sim/aoi_service.py +2 -1
- pycityagent/environment/sim/clock_service.py +2 -1
- pycityagent/environment/sim/economy_services.py +9 -8
- pycityagent/environment/sim/lane_service.py +6 -5
- pycityagent/environment/sim/light_service.py +10 -8
- pycityagent/environment/sim/person_service.py +12 -11
- pycityagent/environment/sim/road_service.py +3 -2
- pycityagent/environment/sim/social_service.py +4 -3
- pycityagent/environment/utils/protobuf.py +6 -4
- pycityagent/memory/memory_base.py +7 -6
- pycityagent/memory/profile.py +7 -6
- pycityagent/memory/self_define.py +8 -7
- pycityagent/memory/state.py +7 -6
- pycityagent/memory/utils.py +2 -1
- pycityagent/utils/parsers/json_parser.py +3 -3
- pycityagent/workflow/block.py +2 -1
- {pycityagent-2.0.0a21.dist-info → pycityagent-2.0.0a22.dist-info}/METADATA +1 -1
- {pycityagent-2.0.0a21.dist-info → pycityagent-2.0.0a22.dist-info}/RECORD +20 -20
- {pycityagent-2.0.0a21.dist-info → pycityagent-2.0.0a22.dist-info}/WHEEL +0 -0
pycityagent/agent.py
CHANGED
@@ -458,13 +458,16 @@ class Agent(ABC):
|
|
458
458
|
topic = f"exps/{self._exp_id}/agents/{to_agent_uuid}/{sub_topic}"
|
459
459
|
await self._messager.send_message(topic, payload)
|
460
460
|
|
461
|
-
async def send_message_to_agent(self, to_agent_uuid: str, content: str):
|
461
|
+
async def send_message_to_agent(self, to_agent_uuid: str, content: str, type: str = "social"):
|
462
462
|
"""通过 Messager 发送消息"""
|
463
463
|
if self._messager is None:
|
464
464
|
raise RuntimeError("Messager is not set")
|
465
|
+
if type not in ["social", "economy"]:
|
466
|
+
logger.warning(f"Invalid message type: {type}, sent from {self._uuid}")
|
465
467
|
payload = {
|
466
468
|
"from": self._uuid,
|
467
469
|
"content": content,
|
470
|
+
"type": type,
|
468
471
|
"timestamp": int(datetime.now().timestamp() * 1000),
|
469
472
|
"day": await self.simulator.get_simulator_day(),
|
470
473
|
"t": await self.simulator.get_simulator_second_from_start_of_day(),
|
@@ -485,11 +488,11 @@ class Agent(ABC):
|
|
485
488
|
auros.append(_message_dict)
|
486
489
|
pg_list.append((_message_dict, _date_time))
|
487
490
|
# Avro
|
488
|
-
if self._avro_file is not None:
|
491
|
+
if self._avro_file is not None and type == "social":
|
489
492
|
with open(self._avro_file["dialog"], "a+b") as f:
|
490
493
|
fastavro.writer(f, DIALOG_SCHEMA, auros, codec="snappy")
|
491
494
|
# Pg
|
492
|
-
if self._pgsql_writer is not None:
|
495
|
+
if self._pgsql_writer is not None and type == "social":
|
493
496
|
if self._last_asyncio_pg_task is not None:
|
494
497
|
await self._last_asyncio_pg_task
|
495
498
|
_keys = ["id", "day", "t", "type", "speaker", "content", "created_at"]
|
@@ -1,4 +1,5 @@
|
|
1
|
-
from typing import Any,
|
1
|
+
from typing import Any, cast, Union
|
2
|
+
from collections.abc import Awaitable, Coroutine
|
2
3
|
|
3
4
|
import grpc
|
4
5
|
from google.protobuf.json_format import ParseDict
|
@@ -25,7 +26,7 @@ class EconomyPersonService:
|
|
25
26
|
self,
|
26
27
|
req: Union[person_service.GetPersonRequest, dict],
|
27
28
|
dict_return: bool = True,
|
28
|
-
) -> Coroutine[Any, Any, Union[
|
29
|
+
) -> Coroutine[Any, Any, Union[dict[str, Any], person_service.GetPersonResponse]]:
|
29
30
|
"""
|
30
31
|
批量查询人的经济情况(资金、雇佣关系)
|
31
32
|
Query person’s economic situation (funds, employment relationship) in batches
|
@@ -48,7 +49,7 @@ class EconomyPersonService:
|
|
48
49
|
req: Union[person_service.UpdatePersonMoneyRequest, dict],
|
49
50
|
dict_return: bool = True,
|
50
51
|
) -> Coroutine[
|
51
|
-
Any, Any, Union[
|
52
|
+
Any, Any, Union[dict[str, Any], person_service.UpdatePersonMoneyResponse]
|
52
53
|
]:
|
53
54
|
"""
|
54
55
|
批量修改人的资金
|
@@ -80,7 +81,7 @@ class EconomyOrgService:
|
|
80
81
|
|
81
82
|
def GetOrg(
|
82
83
|
self, req: Union[org_service.GetOrgRequest, dict], dict_return: bool = True
|
83
|
-
) -> Coroutine[Any, Any, Union[
|
84
|
+
) -> Coroutine[Any, Any, Union[dict[str, Any], org_service.GetOrgResponse]]:
|
84
85
|
"""
|
85
86
|
批量查询组织的经济情况(员工、岗位、资金、货物)
|
86
87
|
Query the economic status of the organization (employees, positions, funds, goods) in batches
|
@@ -100,7 +101,7 @@ class EconomyOrgService:
|
|
100
101
|
self,
|
101
102
|
req: Union[org_service.UpdateOrgMoneyRequest, dict],
|
102
103
|
dict_return: bool = True,
|
103
|
-
) -> Coroutine[Any, Any, Union[
|
104
|
+
) -> Coroutine[Any, Any, Union[dict[str, Any], org_service.UpdateOrgMoneyResponse]]:
|
104
105
|
"""
|
105
106
|
批量修改组织的资金
|
106
107
|
Modify organization’s money in batches
|
@@ -123,7 +124,7 @@ class EconomyOrgService:
|
|
123
124
|
self,
|
124
125
|
req: Union[org_service.UpdateOrgGoodsRequest, dict],
|
125
126
|
dict_return: bool = True,
|
126
|
-
) -> Coroutine[Any, Any, Union[
|
127
|
+
) -> Coroutine[Any, Any, Union[dict[str, Any], org_service.UpdateOrgGoodsResponse]]:
|
127
128
|
"""
|
128
129
|
批量修改组织的货物
|
129
130
|
Modify organization’s goods in batches
|
@@ -147,7 +148,7 @@ class EconomyOrgService:
|
|
147
148
|
req: Union[org_service.UpdateOrgEmployeeRequest, dict],
|
148
149
|
dict_return: bool = True,
|
149
150
|
) -> Coroutine[
|
150
|
-
Any, Any, Union[
|
151
|
+
Any, Any, Union[dict[str, Any], org_service.UpdateOrgEmployeeResponse]
|
151
152
|
]:
|
152
153
|
"""
|
153
154
|
批量修改组织的员工
|
@@ -171,7 +172,7 @@ class EconomyOrgService:
|
|
171
172
|
self,
|
172
173
|
req: Union[org_service.UpdateOrgJobRequest, dict],
|
173
174
|
dict_return: bool = True,
|
174
|
-
) -> Coroutine[Any, Any, Union[
|
175
|
+
) -> Coroutine[Any, Any, Union[dict[str, Any], org_service.UpdateOrgJobResponse]]:
|
175
176
|
"""
|
176
177
|
批量修改组织的岗位
|
177
178
|
Modify organization’s jobs in batches
|
@@ -1,4 +1,5 @@
|
|
1
|
-
from typing import Any,
|
1
|
+
from typing import Any,cast, Union
|
2
|
+
from collections.abc import Awaitable, Coroutine
|
2
3
|
|
3
4
|
import grpc
|
4
5
|
from google.protobuf.json_format import ParseDict
|
@@ -21,7 +22,7 @@ class LaneService:
|
|
21
22
|
|
22
23
|
def GetLane(
|
23
24
|
self, req: Union[lane_service.GetLaneRequest, dict], dict_return: bool = True
|
24
|
-
) -> Coroutine[Any, Any, Union[
|
25
|
+
) -> Coroutine[Any, Any, Union[dict[str, Any], lane_service.GetLaneResponse]]:
|
25
26
|
"""
|
26
27
|
获取Lane的信息
|
27
28
|
Get Lane's information
|
@@ -41,7 +42,7 @@ class LaneService:
|
|
41
42
|
self,
|
42
43
|
req: Union[lane_service.SetLaneMaxVRequest, dict],
|
43
44
|
dict_return: bool = True,
|
44
|
-
) -> Coroutine[Any, Any, Union[
|
45
|
+
) -> Coroutine[Any, Any, Union[dict[str, Any], lane_service.SetLaneMaxVResponse]]:
|
45
46
|
"""
|
46
47
|
设置Lane的最大速度(限速)
|
47
48
|
Set the maximum speed of Lane (speed limit)
|
@@ -64,7 +65,7 @@ class LaneService:
|
|
64
65
|
req: Union[lane_service.SetLaneRestrictionRequest, dict],
|
65
66
|
dict_return: bool = True,
|
66
67
|
) -> Coroutine[
|
67
|
-
Any, Any, Union[
|
68
|
+
Any, Any, Union[dict[str, Any], lane_service.SetLaneRestrictionResponse]
|
68
69
|
]:
|
69
70
|
"""
|
70
71
|
设置Lane的限制
|
@@ -89,7 +90,7 @@ class LaneService:
|
|
89
90
|
req: Union[lane_service.GetLaneByLongLatBBoxRequest, dict],
|
90
91
|
dict_return: bool = True,
|
91
92
|
) -> Coroutine[
|
92
|
-
Any, Any, Union[
|
93
|
+
Any, Any, Union[dict[str, Any], lane_service.GetLaneByLongLatBBoxResponse]
|
93
94
|
]:
|
94
95
|
"""
|
95
96
|
获取特定区域内的Lane的信息
|
@@ -1,9 +1,11 @@
|
|
1
|
-
from
|
1
|
+
from collections.abc import Awaitable, Coroutine
|
2
|
+
from typing import Any, Union, cast
|
2
3
|
|
3
4
|
import grpc
|
4
5
|
from google.protobuf.json_format import ParseDict
|
5
6
|
from pycityproto.city.map.v2 import traffic_light_service_pb2 as light_service
|
6
|
-
from pycityproto.city.map.v2 import
|
7
|
+
from pycityproto.city.map.v2 import \
|
8
|
+
traffic_light_service_pb2_grpc as light_grpc
|
7
9
|
|
8
10
|
from ..utils.protobuf import async_parse
|
9
11
|
|
@@ -21,10 +23,10 @@ class LightService:
|
|
21
23
|
|
22
24
|
def GetTrafficLight(
|
23
25
|
self,
|
24
|
-
req: Union[light_service.GetTrafficLightRequest,
|
26
|
+
req: Union[light_service.GetTrafficLightRequest, dict[str, Any]],
|
25
27
|
dict_return: bool = True,
|
26
28
|
) -> Coroutine[
|
27
|
-
Any, Any, Union[
|
29
|
+
Any, Any, Union[dict[str, Any], light_service.GetTrafficLightResponse]
|
28
30
|
]:
|
29
31
|
"""
|
30
32
|
获取路口的红绿灯信息
|
@@ -46,10 +48,10 @@ class LightService:
|
|
46
48
|
|
47
49
|
def SetTrafficLight(
|
48
50
|
self,
|
49
|
-
req: Union[light_service.SetTrafficLightRequest,
|
51
|
+
req: Union[light_service.SetTrafficLightRequest, dict[str, Any]],
|
50
52
|
dict_return: bool = True,
|
51
53
|
) -> Coroutine[
|
52
|
-
Any, Any, Union[
|
54
|
+
Any, Any, Union[dict[str, Any], light_service.SetTrafficLightResponse]
|
53
55
|
]:
|
54
56
|
"""
|
55
57
|
设置路口的红绿灯信息
|
@@ -74,7 +76,7 @@ class LightService:
|
|
74
76
|
req: Union[light_service.SetTrafficLightPhaseRequest, dict],
|
75
77
|
dict_return: bool = True,
|
76
78
|
) -> Coroutine[
|
77
|
-
Any, Any, Union[
|
79
|
+
Any, Any, Union[dict[str, Any], light_service.SetTrafficLightPhaseResponse]
|
78
80
|
]:
|
79
81
|
"""
|
80
82
|
设置路口的红绿灯相位
|
@@ -99,7 +101,7 @@ class LightService:
|
|
99
101
|
req: Union[light_service.SetTrafficLightStatusRequest, dict],
|
100
102
|
dict_return: bool = True,
|
101
103
|
) -> Coroutine[
|
102
|
-
Any, Any, Union[
|
104
|
+
Any, Any, Union[dict[str, Any], light_service.SetTrafficLightStatusResponse]
|
103
105
|
]:
|
104
106
|
"""
|
105
107
|
设置路口的红绿灯状态
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import warnings
|
2
|
-
from
|
2
|
+
from collections.abc import Awaitable, Coroutine
|
3
|
+
from typing import Any, Union, cast
|
3
4
|
|
4
5
|
import grpc
|
5
6
|
from google.protobuf.json_format import ParseDict
|
@@ -51,7 +52,7 @@ class PersonService:
|
|
51
52
|
self,
|
52
53
|
req: Union[person_service.GetPersonRequest, dict],
|
53
54
|
dict_return: bool = True,
|
54
|
-
) -> Coroutine[Any, Any, Union[
|
55
|
+
) -> Coroutine[Any, Any, Union[dict[str, Any], person_service.GetPersonResponse]]:
|
55
56
|
"""
|
56
57
|
获取person信息
|
57
58
|
Get person information
|
@@ -73,7 +74,7 @@ class PersonService:
|
|
73
74
|
self,
|
74
75
|
req: Union[person_service.AddPersonRequest, dict],
|
75
76
|
dict_return: bool = True,
|
76
|
-
) -> Coroutine[Any, Any, Union[
|
77
|
+
) -> Coroutine[Any, Any, Union[dict[str, Any], person_service.AddPersonResponse]]:
|
77
78
|
"""
|
78
79
|
新增person
|
79
80
|
Add a new person
|
@@ -95,7 +96,7 @@ class PersonService:
|
|
95
96
|
self,
|
96
97
|
req: Union[person_service.SetScheduleRequest, dict],
|
97
98
|
dict_return: bool = True,
|
98
|
-
) -> Coroutine[Any, Any, Union[
|
99
|
+
) -> Coroutine[Any, Any, Union[dict[str, Any], person_service.SetScheduleResponse]]:
|
99
100
|
"""
|
100
101
|
修改person的schedule
|
101
102
|
set person's schedule
|
@@ -118,7 +119,7 @@ class PersonService:
|
|
118
119
|
self,
|
119
120
|
req: Union[person_service.GetPersonsRequest, dict],
|
120
121
|
dict_return: bool = True,
|
121
|
-
) -> Coroutine[Any, Any, Union[
|
122
|
+
) -> Coroutine[Any, Any, Union[dict[str, Any], person_service.GetPersonsResponse]]:
|
122
123
|
"""
|
123
124
|
获取多个person信息
|
124
125
|
Get information of multiple persons
|
@@ -142,7 +143,7 @@ class PersonService:
|
|
142
143
|
req: Union[person_service.GetPersonByLongLatBBoxRequest, dict],
|
143
144
|
dict_return: bool = True,
|
144
145
|
) -> Coroutine[
|
145
|
-
Any, Any, Union[
|
146
|
+
Any, Any, Union[dict[str, Any], person_service.GetPersonByLongLatBBoxResponse]
|
146
147
|
]:
|
147
148
|
"""
|
148
149
|
获取特定区域内的person
|
@@ -167,7 +168,7 @@ class PersonService:
|
|
167
168
|
req: Union[person_service.GetAllVehiclesRequest, dict],
|
168
169
|
dict_return: bool = True,
|
169
170
|
) -> Coroutine[
|
170
|
-
Any, Any, Union[
|
171
|
+
Any, Any, Union[dict[str, Any], person_service.GetAllVehiclesResponse]
|
171
172
|
]:
|
172
173
|
"""
|
173
174
|
获取所有车辆
|
@@ -192,7 +193,7 @@ class PersonService:
|
|
192
193
|
req: Union[person_service.ResetPersonPositionRequest, dict],
|
193
194
|
dict_return: bool = True,
|
194
195
|
) -> Coroutine[
|
195
|
-
Any, Any, Union[
|
196
|
+
Any, Any, Union[dict[str, Any], person_service.ResetPersonPositionResponse]
|
196
197
|
]:
|
197
198
|
"""
|
198
199
|
重置人的位置(将停止当前正在进行的出行,转为sleep状态)
|
@@ -219,7 +220,7 @@ class PersonService:
|
|
219
220
|
req: Union[person_service.SetControlledVehicleIDsRequest, dict],
|
220
221
|
dict_return: bool = True,
|
221
222
|
) -> Coroutine[
|
222
|
-
Any, Any, Union[
|
223
|
+
Any, Any, Union[dict[str, Any], person_service.SetControlledVehicleIDsResponse]
|
223
224
|
]:
|
224
225
|
"""
|
225
226
|
设置由外部控制行为的vehicle
|
@@ -246,7 +247,7 @@ class PersonService:
|
|
246
247
|
) -> Coroutine[
|
247
248
|
Any,
|
248
249
|
Any,
|
249
|
-
Union[
|
250
|
+
Union[dict[str, Any], person_service.FetchControlledVehicleEnvsResponse],
|
250
251
|
]:
|
251
252
|
"""
|
252
253
|
获取由外部控制行为的vehicle的环境信息
|
@@ -273,7 +274,7 @@ class PersonService:
|
|
273
274
|
) -> Coroutine[
|
274
275
|
Any,
|
275
276
|
Any,
|
276
|
-
Union[
|
277
|
+
Union[dict[str, Any], person_service.SetControlledVehicleActionsResponse],
|
277
278
|
]:
|
278
279
|
"""
|
279
280
|
设置由外部控制行为的vehicle的行为
|
@@ -1,4 +1,5 @@
|
|
1
|
-
from
|
1
|
+
from collections.abc import Awaitable, Coroutine
|
2
|
+
from typing import Any, Union, cast
|
2
3
|
|
3
4
|
import grpc
|
4
5
|
from google.protobuf.json_format import ParseDict
|
@@ -21,7 +22,7 @@ class RoadService:
|
|
21
22
|
|
22
23
|
def GetRoad(
|
23
24
|
self, req: Union[road_service.GetRoadRequest, dict], dict_return: bool = True
|
24
|
-
) -> Coroutine[Any, Any, Union[
|
25
|
+
) -> Coroutine[Any, Any, Union[dict[str, Any], road_service.GetRoadResponse]]:
|
25
26
|
"""
|
26
27
|
查询道路信息
|
27
28
|
Query road information
|
@@ -1,4 +1,5 @@
|
|
1
|
-
from
|
1
|
+
from collections.abc import Awaitable, Coroutine
|
2
|
+
from typing import Any, Union, cast
|
2
3
|
|
3
4
|
import grpc
|
4
5
|
from google.protobuf.json_format import ParseDict
|
@@ -21,7 +22,7 @@ class SocialService:
|
|
21
22
|
|
22
23
|
def Send(
|
23
24
|
self, req: Union[social_service.SendRequest, dict], dict_return: bool = True
|
24
|
-
) -> Coroutine[Any, Any, Union[
|
25
|
+
) -> Coroutine[Any, Any, Union[dict[str, Any], social_service.SendResponse]]:
|
25
26
|
"""
|
26
27
|
发送消息
|
27
28
|
Send message
|
@@ -39,7 +40,7 @@ class SocialService:
|
|
39
40
|
|
40
41
|
def Receive(
|
41
42
|
self, req: Union[social_service.ReceiveRequest, dict], dict_return: bool = True
|
42
|
-
) -> Coroutine[Any, Any, Union[
|
43
|
+
) -> Coroutine[Any, Any, Union[dict[str, Any], social_service.ReceiveResponse]]:
|
43
44
|
"""
|
44
45
|
接收消息
|
45
46
|
Receive message
|
@@ -1,13 +1,15 @@
|
|
1
|
-
from
|
2
|
-
from
|
1
|
+
from collections.abc import Awaitable
|
2
|
+
from typing import Any, TypeVar, Union
|
3
|
+
|
3
4
|
from google.protobuf.json_format import MessageToDict
|
5
|
+
from google.protobuf.message import Message
|
4
6
|
|
5
7
|
__all__ = ["parse", "async_parse"]
|
6
8
|
|
7
9
|
T = TypeVar("T", bound=Message)
|
8
10
|
|
9
11
|
|
10
|
-
def parse(res: T, dict_return: bool) -> Union[
|
12
|
+
def parse(res: T, dict_return: bool) -> Union[dict[str, Any], T]:
|
11
13
|
"""
|
12
14
|
将Protobuf返回值转换为dict或者原始值
|
13
15
|
Convert Protobuf return value to dict or original value
|
@@ -23,7 +25,7 @@ def parse(res: T, dict_return: bool) -> Union[Dict[str, Any], T]:
|
|
23
25
|
return res
|
24
26
|
|
25
27
|
|
26
|
-
async def async_parse(res: Awaitable[T], dict_return: bool) -> Union[
|
28
|
+
async def async_parse(res: Awaitable[T], dict_return: bool) -> Union[dict[str, Any], T]:
|
27
29
|
"""
|
28
30
|
将Protobuf await返回值转换为dict或者原始值
|
29
31
|
Convert Protobuf await return value to dict or original value
|
@@ -6,7 +6,8 @@ import asyncio
|
|
6
6
|
import logging
|
7
7
|
import time
|
8
8
|
from abc import ABC, abstractmethod
|
9
|
-
from
|
9
|
+
from collections.abc import Callable, Sequence
|
10
|
+
from typing import Any, Optional, Union
|
10
11
|
|
11
12
|
from .const import *
|
12
13
|
|
@@ -16,8 +17,8 @@ logger = logging.getLogger("pycityagent")
|
|
16
17
|
class MemoryUnit:
|
17
18
|
def __init__(
|
18
19
|
self,
|
19
|
-
content: Optional[
|
20
|
-
required_attributes: Optional[
|
20
|
+
content: Optional[dict] = None,
|
21
|
+
required_attributes: Optional[dict] = None,
|
21
22
|
activate_timestamp: bool = False,
|
22
23
|
) -> None:
|
23
24
|
self._content = {}
|
@@ -52,7 +53,7 @@ class MemoryUnit:
|
|
52
53
|
else:
|
53
54
|
setattr(self, f"{SELF_DEFINE_PREFIX}{property_name}", property_value)
|
54
55
|
|
55
|
-
async def update(self, content:
|
56
|
+
async def update(self, content: dict) -> None:
|
56
57
|
await self._lock.acquire()
|
57
58
|
for k, v in content.items():
|
58
59
|
if k in self._content:
|
@@ -111,14 +112,14 @@ class MemoryUnit:
|
|
111
112
|
|
112
113
|
async def dict_values(
|
113
114
|
self,
|
114
|
-
) ->
|
115
|
+
) -> dict[Any, Any]:
|
115
116
|
return self._content
|
116
117
|
|
117
118
|
|
118
119
|
class MemoryBase(ABC):
|
119
120
|
|
120
121
|
def __init__(self) -> None:
|
121
|
-
self._memories:
|
122
|
+
self._memories: dict[Any, dict] = {}
|
122
123
|
self._lock = asyncio.Lock()
|
123
124
|
|
124
125
|
@abstractmethod
|
pycityagent/memory/profile.py
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
Agent Profile
|
3
3
|
"""
|
4
4
|
|
5
|
+
from collections.abc import Callable, Sequence
|
5
6
|
from copy import deepcopy
|
6
|
-
from typing import Any,
|
7
|
+
from typing import Any, Optional, Union, cast
|
7
8
|
|
8
9
|
from ..utils.decorators import lock_decorator
|
9
10
|
from .const import *
|
@@ -14,7 +15,7 @@ from .utils import convert_msg_to_sequence
|
|
14
15
|
class ProfileMemoryUnit(MemoryUnit):
|
15
16
|
def __init__(
|
16
17
|
self,
|
17
|
-
content: Optional[
|
18
|
+
content: Optional[dict] = None,
|
18
19
|
activate_timestamp: bool = False,
|
19
20
|
) -> None:
|
20
21
|
super().__init__(
|
@@ -28,7 +29,7 @@ class ProfileMemory(MemoryBase):
|
|
28
29
|
def __init__(
|
29
30
|
self,
|
30
31
|
msg: Optional[
|
31
|
-
Union[ProfileMemoryUnit, Sequence[ProfileMemoryUnit],
|
32
|
+
Union[ProfileMemoryUnit, Sequence[ProfileMemoryUnit], dict, Sequence[dict]]
|
32
33
|
] = None,
|
33
34
|
activate_timestamp: bool = False,
|
34
35
|
) -> None:
|
@@ -74,7 +75,7 @@ class ProfileMemory(MemoryBase):
|
|
74
75
|
@lock_decorator
|
75
76
|
async def load(
|
76
77
|
self,
|
77
|
-
snapshots: Union[
|
78
|
+
snapshots: Union[dict, Sequence[dict]],
|
78
79
|
reset_memory: bool = False,
|
79
80
|
) -> None:
|
80
81
|
if reset_memory:
|
@@ -91,7 +92,7 @@ class ProfileMemory(MemoryBase):
|
|
91
92
|
@lock_decorator
|
92
93
|
async def export(
|
93
94
|
self,
|
94
|
-
) -> Sequence[
|
95
|
+
) -> Sequence[dict]:
|
95
96
|
_res = []
|
96
97
|
for m in self._memories.keys():
|
97
98
|
m = cast(ProfileMemoryUnit, m)
|
@@ -145,7 +146,7 @@ class ProfileMemory(MemoryBase):
|
|
145
146
|
self._memories[unit] = {}
|
146
147
|
|
147
148
|
@lock_decorator
|
148
|
-
async def update_dict(self, to_update_dict:
|
149
|
+
async def update_dict(self, to_update_dict: dict, store_snapshot: bool = False):
|
149
150
|
_latest_memories = self._fetch_recent_memory()
|
150
151
|
_latest_memory: ProfileMemoryUnit = _latest_memories[-1]
|
151
152
|
if not store_snapshot:
|
@@ -2,8 +2,9 @@
|
|
2
2
|
Self Define Data
|
3
3
|
"""
|
4
4
|
|
5
|
+
from collections.abc import Callable, Sequence
|
5
6
|
from copy import deepcopy
|
6
|
-
from typing import Any,
|
7
|
+
from typing import Any, Optional, Union, cast
|
7
8
|
|
8
9
|
from ..utils.decorators import lock_decorator
|
9
10
|
from .const import *
|
@@ -14,8 +15,8 @@ from .utils import convert_msg_to_sequence
|
|
14
15
|
class DynamicMemoryUnit(MemoryUnit):
|
15
16
|
def __init__(
|
16
17
|
self,
|
17
|
-
content: Optional[
|
18
|
-
required_attributes: Optional[
|
18
|
+
content: Optional[dict] = None,
|
19
|
+
required_attributes: Optional[dict] = None,
|
19
20
|
activate_timestamp: bool = False,
|
20
21
|
) -> None:
|
21
22
|
super().__init__(
|
@@ -29,7 +30,7 @@ class DynamicMemory(MemoryBase):
|
|
29
30
|
|
30
31
|
def __init__(
|
31
32
|
self,
|
32
|
-
required_attributes:
|
33
|
+
required_attributes: dict[Any, Any],
|
33
34
|
activate_timestamp: bool = False,
|
34
35
|
) -> None:
|
35
36
|
super().__init__()
|
@@ -69,7 +70,7 @@ class DynamicMemory(MemoryBase):
|
|
69
70
|
@lock_decorator
|
70
71
|
async def load(
|
71
72
|
self,
|
72
|
-
snapshots: Union[
|
73
|
+
snapshots: Union[dict, Sequence[dict]],
|
73
74
|
reset_memory: bool = False,
|
74
75
|
) -> None:
|
75
76
|
if reset_memory:
|
@@ -86,7 +87,7 @@ class DynamicMemory(MemoryBase):
|
|
86
87
|
@lock_decorator
|
87
88
|
async def export(
|
88
89
|
self,
|
89
|
-
) -> Sequence[
|
90
|
+
) -> Sequence[dict]:
|
90
91
|
_res = []
|
91
92
|
for m in self._memories.keys():
|
92
93
|
m = cast(DynamicMemoryUnit, m)
|
@@ -143,7 +144,7 @@ class DynamicMemory(MemoryBase):
|
|
143
144
|
self._memories[unit] = {}
|
144
145
|
|
145
146
|
@lock_decorator
|
146
|
-
async def update_dict(self, to_update_dict:
|
147
|
+
async def update_dict(self, to_update_dict: dict, store_snapshot: bool = False):
|
147
148
|
_latest_memories = self._fetch_recent_memory()
|
148
149
|
_latest_memory: DynamicMemoryUnit = _latest_memories[-1]
|
149
150
|
if not store_snapshot:
|
pycityagent/memory/state.py
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
Agent State
|
3
3
|
"""
|
4
4
|
|
5
|
+
from collections.abc import Callable, Sequence
|
5
6
|
from copy import deepcopy
|
6
|
-
from typing import Any,
|
7
|
+
from typing import Any, Optional, Union, cast
|
7
8
|
|
8
9
|
from ..utils.decorators import lock_decorator
|
9
10
|
from .const import *
|
@@ -14,7 +15,7 @@ from .utils import convert_msg_to_sequence
|
|
14
15
|
class StateMemoryUnit(MemoryUnit):
|
15
16
|
def __init__(
|
16
17
|
self,
|
17
|
-
content: Optional[
|
18
|
+
content: Optional[dict] = None,
|
18
19
|
activate_timestamp: bool = False,
|
19
20
|
) -> None:
|
20
21
|
super().__init__(
|
@@ -28,7 +29,7 @@ class StateMemory(MemoryBase):
|
|
28
29
|
def __init__(
|
29
30
|
self,
|
30
31
|
msg: Optional[
|
31
|
-
Union[MemoryUnit, Sequence[MemoryUnit],
|
32
|
+
Union[MemoryUnit, Sequence[MemoryUnit], dict, Sequence[dict]]
|
32
33
|
] = None,
|
33
34
|
activate_timestamp: bool = False,
|
34
35
|
) -> None:
|
@@ -73,7 +74,7 @@ class StateMemory(MemoryBase):
|
|
73
74
|
@lock_decorator
|
74
75
|
async def load(
|
75
76
|
self,
|
76
|
-
snapshots: Union[
|
77
|
+
snapshots: Union[dict, Sequence[dict]],
|
77
78
|
reset_memory: bool = False,
|
78
79
|
) -> None:
|
79
80
|
|
@@ -91,7 +92,7 @@ class StateMemory(MemoryBase):
|
|
91
92
|
@lock_decorator
|
92
93
|
async def export(
|
93
94
|
self,
|
94
|
-
) -> Sequence[
|
95
|
+
) -> Sequence[dict]:
|
95
96
|
|
96
97
|
_res = []
|
97
98
|
for m in self._memories.keys():
|
@@ -151,7 +152,7 @@ class StateMemory(MemoryBase):
|
|
151
152
|
self._memories[unit] = {}
|
152
153
|
|
153
154
|
@lock_decorator
|
154
|
-
async def update_dict(self, to_update_dict:
|
155
|
+
async def update_dict(self, to_update_dict: dict, store_snapshot: bool = False):
|
155
156
|
|
156
157
|
_latest_memories = self._fetch_recent_memory()
|
157
158
|
_latest_memory: StateMemoryUnit = _latest_memories[-1]
|
pycityagent/memory/utils.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import json
|
2
2
|
import logging
|
3
|
-
from typing import Any
|
3
|
+
from typing import Any
|
4
4
|
|
5
5
|
from .parser_base import ParserBase
|
6
6
|
|
@@ -67,14 +67,14 @@ class JsonDictParser(JsonObjectParser):
|
|
67
67
|
"""Initialize the JsonDictParser with default tags."""
|
68
68
|
super().__init__()
|
69
69
|
|
70
|
-
def parse(self, response: str) ->
|
70
|
+
def parse(self, response: str) -> dict:
|
71
71
|
"""Parse the response string to extract and return a JSON object as a dictionary.
|
72
72
|
|
73
73
|
Parameters:
|
74
74
|
response (str): The response string containing the JSON object.
|
75
75
|
|
76
76
|
Returns:
|
77
|
-
|
77
|
+
dict: The parsed JSON object as a dictionary.
|
78
78
|
"""
|
79
79
|
parsed_json = super().parse(response)
|
80
80
|
if not isinstance(parsed_json, dict):
|
pycityagent/workflow/block.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
import asyncio
|
2
2
|
import functools
|
3
3
|
import inspect
|
4
|
-
from
|
4
|
+
from collections.abc import Awaitable, Callable, Coroutine
|
5
|
+
from typing import Any, Optional, Union
|
5
6
|
|
6
7
|
from ..environment.simulator import Simulator
|
7
8
|
from ..llm import LLM
|
@@ -1,5 +1,5 @@
|
|
1
1
|
pycityagent/__init__.py,sha256=EDxt3Su3lH1IMh9suNw7GeGL7UrXeWiZTw5KWNznDzc,637
|
2
|
-
pycityagent/agent.py,sha256=
|
2
|
+
pycityagent/agent.py,sha256=TGW4vyaYBnNxYkr22FhGPwex3dLIeq3F-2rnELidNPA,28670
|
3
3
|
pycityagent/economy/__init__.py,sha256=aonY4WHnx-6EGJ4WKrx4S-2jAkYNLtqUA04jp6q8B7w,75
|
4
4
|
pycityagent/economy/econ_client.py,sha256=GuHK9ZBnhqW3Z7F8ViDJn_iN73yOBbbwFyJv1wLEBDk,12211
|
5
5
|
pycityagent/environment/__init__.py,sha256=awHxlOud-btWbk0FCS4RmGJ13W84oVCkbGfcrhKqihA,240
|
@@ -11,16 +11,16 @@ pycityagent/environment/sence/static.py,sha256=9s7jz8HitstTrk-GqpnVB26oPrjuTyNeL
|
|
11
11
|
pycityagent/environment/sidecar/__init__.py,sha256=RFbOf40aYBP4WwRpFkua5tlRE_OtMcMNyp1Lew_aaAU,235
|
12
12
|
pycityagent/environment/sidecar/sidecarv2.py,sha256=beKlYZgt38EQbV1x6NWQo7xVXyB-5QHfbwJexyXu7Tg,3252
|
13
13
|
pycityagent/environment/sim/__init__.py,sha256=JVG6sSD2Hbohl1TtKjuQi7_M7tKMrFh9vl3QV3VA5O0,724
|
14
|
-
pycityagent/environment/sim/aoi_service.py,sha256=
|
14
|
+
pycityagent/environment/sim/aoi_service.py,sha256=2UjvUTF4CW4E_L30IRcdwv6t_q1ZdXN3TTLOKSOaaXE,1230
|
15
15
|
pycityagent/environment/sim/client.py,sha256=MHR7Hhu-Cr7B61d3K_QDpSJh4HrUU9JQf6Cu7_8pdsE,3493
|
16
|
-
pycityagent/environment/sim/clock_service.py,sha256=
|
17
|
-
pycityagent/environment/sim/economy_services.py,sha256=
|
18
|
-
pycityagent/environment/sim/lane_service.py,sha256=
|
19
|
-
pycityagent/environment/sim/light_service.py,sha256=
|
20
|
-
pycityagent/environment/sim/person_service.py,sha256=
|
21
|
-
pycityagent/environment/sim/road_service.py,sha256=
|
16
|
+
pycityagent/environment/sim/clock_service.py,sha256=fgYXacf_-ixhVAn5uKUvqvemBS6A0oQK8JOZukkhXyY,1353
|
17
|
+
pycityagent/environment/sim/economy_services.py,sha256=xoc-1_H8JmQwJ24oWRS1fD-hGYtz2I-x6BOkQ4yENzU,7106
|
18
|
+
pycityagent/environment/sim/lane_service.py,sha256=N2dUe-3XuqqKLsNXt1k4NN8uV-J_ruo08yhaUd_hwOI,3916
|
19
|
+
pycityagent/environment/sim/light_service.py,sha256=KVwt7ii_iLGA7gANZe3n6-4RiiPQt1w9H6ZOoizMI04,4242
|
20
|
+
pycityagent/environment/sim/person_service.py,sha256=5r1F2Itn7dKJ2U4hSLovrk5p4qy-2n77MTAv_OlTIwA,10673
|
21
|
+
pycityagent/environment/sim/road_service.py,sha256=bKyn3_me0sGmaJVyF6eNeFbdU-9C1yWsa9L7pieDJzg,1285
|
22
22
|
pycityagent/environment/sim/sim_env.py,sha256=HI1LcS_FotDKQ6vBnx0e49prXSABOfA20aU9KM-ZkCY,4625
|
23
|
-
pycityagent/environment/sim/social_service.py,sha256=
|
23
|
+
pycityagent/environment/sim/social_service.py,sha256=9EFJAwVdUuUQkNkFRn9qZRDfD1brh2fqkvasnXUEBhQ,2014
|
24
24
|
pycityagent/environment/simulator.py,sha256=XjcxbyBIbB3Ht9z087z_oWIPAN6pP5Eq1lyf4W5atb8,12502
|
25
25
|
pycityagent/environment/utils/__init__.py,sha256=1m4Q1EfGvNpUsa1bgQzzCyWhfkpElnskNImjjFD3Znc,237
|
26
26
|
pycityagent/environment/utils/base64.py,sha256=hoREzQo3FXMN79pqQLO2jgsDEvudciomyKii7MWljAM,374
|
@@ -29,7 +29,7 @@ pycityagent/environment/utils/geojson.py,sha256=LVHAdEhnZM8d0BoUnuPiIL_gaeXBIIgl
|
|
29
29
|
pycityagent/environment/utils/grpc.py,sha256=6EJwKXXktIWb1NcUiJzIRmfrY0S03QAXXGcCDHqAT00,1998
|
30
30
|
pycityagent/environment/utils/map_utils.py,sha256=lYOEoCFFK6-e9N5txLMMq4HUlxMqc8Uw1YrGW5oJmgg,5749
|
31
31
|
pycityagent/environment/utils/port.py,sha256=3OM6kSUt3PxvDUOlgyiendBtETaWU8Mzk_8H0TzTmYg,295
|
32
|
-
pycityagent/environment/utils/protobuf.py,sha256=
|
32
|
+
pycityagent/environment/utils/protobuf.py,sha256=0BsM_G7x2B_6DMIBHe9bjVuQDOXUytNRQ03g9e05F3c,1170
|
33
33
|
pycityagent/llm/__init__.py,sha256=7klKEmCcDWJIu-F4DoAukSuKfDbLhdczrSIhpwow-sY,145
|
34
34
|
pycityagent/llm/embedding.py,sha256=2psX_EK67oPlYe77g43EYUYams4M9AiJqxpHTFHG0n8,4253
|
35
35
|
pycityagent/llm/llm.py,sha256=vJaaGqVuyV-GlBxrnvGKZnMDlxeTT_sGUTdxz5tYwEE,15141
|
@@ -38,11 +38,11 @@ pycityagent/llm/utils.py,sha256=hoNPhvomb1u6lhFX0GctFipw74hVKb7bvUBDqwBzBYw,160
|
|
38
38
|
pycityagent/memory/__init__.py,sha256=Hs2NhYpIG-lvpwPWwj4DydB1sxtjz7cuA4iDAzCXnjI,243
|
39
39
|
pycityagent/memory/const.py,sha256=6zpJPJXWoH9-yf4RARYYff586agCoud9BRn7sPERB1g,932
|
40
40
|
pycityagent/memory/memory.py,sha256=vJxHOI74aJDGZPFu2LbBr02ASfOYpig66fto6Gjr-6Q,18191
|
41
|
-
pycityagent/memory/memory_base.py,sha256=
|
42
|
-
pycityagent/memory/profile.py,sha256=
|
43
|
-
pycityagent/memory/self_define.py,sha256=
|
44
|
-
pycityagent/memory/state.py,sha256=
|
45
|
-
pycityagent/memory/utils.py,sha256=
|
41
|
+
pycityagent/memory/memory_base.py,sha256=QG_j3BxZvkadFEeE3uBR_kjl_xcXD1aHUVs8GEF3d6w,5654
|
42
|
+
pycityagent/memory/profile.py,sha256=q8ZS9IBmHCg_X1GONUvXK85P6tCepTKQgXKuvuXYNXw,5203
|
43
|
+
pycityagent/memory/self_define.py,sha256=vpZ6CIxR2grNXEIOScdpsSc59FBg0mOKelwQuTElbtQ,5200
|
44
|
+
pycityagent/memory/state.py,sha256=TYItiyDtehMEQaSBN7PpNrnNxdDM5jGppr9R9Ufv3kA,5134
|
45
|
+
pycityagent/memory/utils.py,sha256=oJWLdPeJy_jcdKcDTo9JAH9kDZhqjoQhhv_zT9qWC0w,877
|
46
46
|
pycityagent/message/__init__.py,sha256=TCjazxqb5DVwbTu1fF0sNvaH_EPXVuj2XQ0p6W-QCLU,55
|
47
47
|
pycityagent/message/messager.py,sha256=W_OVlNGcreHSBf6v-DrEnfNCXExB78ySr0w26MSncfU,2541
|
48
48
|
pycityagent/metrics/__init__.py,sha256=X08PaBbGVAd7_PRGLREXWxaqm7nS82WBQpD1zvQzcqc,128
|
@@ -60,15 +60,15 @@ pycityagent/utils/avro_schema.py,sha256=DHM3bOo8m0dJf8oSwyOWzVeXrH6OERmzA_a5vS4S
|
|
60
60
|
pycityagent/utils/decorators.py,sha256=Gk3r41hfk6awui40tbwpq3C7wC7jHaRmLRlcJFlLQCE,3160
|
61
61
|
pycityagent/utils/parsers/__init__.py,sha256=AN2xgiPxszWK4rpX7zrqRsqNwfGF3WnCA5-PFTvbaKk,281
|
62
62
|
pycityagent/utils/parsers/code_block_parser.py,sha256=Cs2Z_hm9VfNCpPPll1TwteaJF-HAQPs-3RApsOekFm4,1173
|
63
|
-
pycityagent/utils/parsers/json_parser.py,sha256=
|
63
|
+
pycityagent/utils/parsers/json_parser.py,sha256=tjwyPluYfkWgsvLi0hzfJwFhO3L6yQfZMKza20HaGrY,2911
|
64
64
|
pycityagent/utils/parsers/parser_base.py,sha256=KBKO4zLZPNdGjPAGqIus8LseZ8W3Tlt2y0QxqeCd25Q,1713
|
65
65
|
pycityagent/utils/pg_query.py,sha256=h5158xcrxjUTR0nKwAaG1neFfTHPbN5guLmaXpC8yvs,1918
|
66
66
|
pycityagent/utils/survey_util.py,sha256=Be9nptmu2JtesFNemPgORh_2GsN7rcDYGQS9Zfvc5OI,2169
|
67
67
|
pycityagent/workflow/__init__.py,sha256=QNkUV-9mACMrR8c0cSKna2gC1mMZdxXbxWzjE-Uods0,621
|
68
|
-
pycityagent/workflow/block.py,sha256=
|
68
|
+
pycityagent/workflow/block.py,sha256=l-z9iJo9_USZQRyj4TLMfihK0-tnNDG0a6jVk9WhG0o,6048
|
69
69
|
pycityagent/workflow/prompt.py,sha256=6jI0Rq54JLv3-IXqZLYug62vse10wTI83xvf4ZX42nk,2929
|
70
70
|
pycityagent/workflow/tool.py,sha256=xADxhNgVsjNiMxlhdwn3xGUstFOkLEG8P67ez8VmwSI,8555
|
71
71
|
pycityagent/workflow/trigger.py,sha256=Df-MOBEDWBbM-v0dFLQLXteLsipymT4n8vqexmK2GiQ,5643
|
72
|
-
pycityagent-2.0.
|
73
|
-
pycityagent-2.0.
|
74
|
-
pycityagent-2.0.
|
72
|
+
pycityagent-2.0.0a22.dist-info/METADATA,sha256=s_gC55n1d1ZUyt1kRcYhl7h9Ymp8BQQKXZHrg93V8sg,7848
|
73
|
+
pycityagent-2.0.0a22.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
74
|
+
pycityagent-2.0.0a22.dist-info/RECORD,,
|
File without changes
|