pycityagent 2.0.0a93__cp39-cp39-macosx_11_0_arm64.whl → 2.0.0a95__cp39-cp39-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.
- pycityagent/agent/agent.py +5 -5
- pycityagent/agent/agent_base.py +1 -2
- pycityagent/cityagent/__init__.py +6 -5
- pycityagent/cityagent/bankagent.py +2 -2
- pycityagent/cityagent/blocks/__init__.py +4 -4
- pycityagent/cityagent/blocks/cognition_block.py +7 -4
- pycityagent/cityagent/blocks/economy_block.py +227 -135
- pycityagent/cityagent/blocks/mobility_block.py +70 -27
- pycityagent/cityagent/blocks/needs_block.py +11 -12
- pycityagent/cityagent/blocks/other_block.py +2 -2
- pycityagent/cityagent/blocks/plan_block.py +22 -24
- pycityagent/cityagent/blocks/social_block.py +15 -17
- pycityagent/cityagent/blocks/utils.py +3 -2
- pycityagent/cityagent/firmagent.py +1 -1
- pycityagent/cityagent/governmentagent.py +1 -1
- pycityagent/cityagent/initial.py +1 -1
- pycityagent/cityagent/memory_config.py +0 -1
- pycityagent/cityagent/message_intercept.py +7 -8
- pycityagent/cityagent/nbsagent.py +1 -1
- pycityagent/cityagent/societyagent.py +1 -2
- pycityagent/configs/__init__.py +18 -0
- pycityagent/configs/exp_config.py +202 -0
- pycityagent/configs/sim_config.py +251 -0
- pycityagent/configs/utils.py +17 -0
- pycityagent/environment/__init__.py +2 -0
- pycityagent/{economy → environment/economy}/econ_client.py +14 -32
- pycityagent/environment/sim/sim_env.py +17 -24
- pycityagent/environment/simulator.py +36 -113
- pycityagent/llm/__init__.py +1 -2
- pycityagent/llm/llm.py +60 -166
- pycityagent/memory/memory.py +13 -12
- pycityagent/message/message_interceptor.py +5 -4
- pycityagent/message/messager.py +3 -5
- pycityagent/metrics/__init__.py +1 -1
- pycityagent/metrics/mlflow_client.py +20 -17
- pycityagent/pycityagent-sim +0 -0
- pycityagent/simulation/agentgroup.py +17 -19
- pycityagent/simulation/simulation.py +157 -210
- pycityagent/survey/manager.py +0 -2
- pycityagent/utils/__init__.py +3 -0
- pycityagent/utils/config_const.py +20 -0
- pycityagent/workflow/__init__.py +1 -2
- pycityagent/workflow/block.py +0 -3
- {pycityagent-2.0.0a93.dist-info → pycityagent-2.0.0a95.dist-info}/METADATA +7 -24
- {pycityagent-2.0.0a93.dist-info → pycityagent-2.0.0a95.dist-info}/RECORD +50 -46
- pycityagent/llm/llmconfig.py +0 -18
- /pycityagent/{economy → environment/economy}/__init__.py +0 -0
- {pycityagent-2.0.0a93.dist-info → pycityagent-2.0.0a95.dist-info}/LICENSE +0 -0
- {pycityagent-2.0.0a93.dist-info → pycityagent-2.0.0a95.dist-info}/WHEEL +0 -0
- {pycityagent-2.0.0a93.dist-info → pycityagent-2.0.0a95.dist-info}/entry_points.txt +0 -0
- {pycityagent-2.0.0a93.dist-info → pycityagent-2.0.0a95.dist-info}/top_level.txt +0 -0
pycityagent/agent/agent.py
CHANGED
@@ -6,12 +6,10 @@ import random
|
|
6
6
|
from copy import deepcopy
|
7
7
|
from typing import Any, Optional
|
8
8
|
|
9
|
-
from mosstool.util.format_converter import dict2pb
|
10
|
-
from pycityproto.city.person.v2 import person_pb2 as person_pb2
|
11
9
|
import ray
|
10
|
+
from pycityproto.city.person.v2 import person_pb2 as person_pb2
|
12
11
|
|
13
|
-
from ..
|
14
|
-
from ..environment import Simulator
|
12
|
+
from ..environment import EconomyClient, Simulator
|
15
13
|
from ..llm import LLM
|
16
14
|
from ..memory import Memory
|
17
15
|
from ..message import MessageInterceptor, Messager
|
@@ -281,7 +279,9 @@ class InstitutionAgent(Agent):
|
|
281
279
|
_id = random.randint(100000, 999999)
|
282
280
|
self._agent_id = _id
|
283
281
|
self.status.set_agent_id(_id)
|
284
|
-
map_header = ray.get(
|
282
|
+
map_header: dict = ray.get(
|
283
|
+
self.simulator.map.get_map_header.remote() # type:ignore
|
284
|
+
)
|
285
285
|
# TODO: remove random position assignment
|
286
286
|
await self.status.update(
|
287
287
|
"position",
|
pycityagent/agent/agent_base.py
CHANGED
@@ -14,8 +14,7 @@ import fastavro
|
|
14
14
|
import ray
|
15
15
|
from pycityproto.city.person.v2 import person_pb2 as person_pb2
|
16
16
|
|
17
|
-
from ..
|
18
|
-
from ..environment import Simulator
|
17
|
+
from ..environment import EconomyClient, Simulator
|
19
18
|
from ..environment.sim.person_service import PersonService
|
20
19
|
from ..llm import LLM
|
21
20
|
from ..memory import Memory
|
@@ -1,9 +1,11 @@
|
|
1
|
-
from .societyagent import SocietyAgent
|
2
|
-
from .firmagent import FirmAgent
|
3
1
|
from .bankagent import BankAgent
|
4
|
-
from .
|
2
|
+
from .firmagent import FirmAgent
|
5
3
|
from .governmentagent import GovernmentAgent
|
6
|
-
from .memory_config import
|
4
|
+
from .memory_config import (memory_config_bank, memory_config_firm,
|
5
|
+
memory_config_government, memory_config_nbs,
|
6
|
+
memory_config_societyagent)
|
7
|
+
from .nbsagent import NBSAgent
|
8
|
+
from .societyagent import SocietyAgent
|
7
9
|
|
8
10
|
__all__ = [
|
9
11
|
"SocietyAgent",
|
@@ -17,4 +19,3 @@ __all__ = [
|
|
17
19
|
"memory_config_bank",
|
18
20
|
"memory_config_nbs",
|
19
21
|
]
|
20
|
-
|
@@ -4,7 +4,7 @@ from typing import Optional
|
|
4
4
|
import numpy as np
|
5
5
|
from pycityagent import Simulator, InstitutionAgent
|
6
6
|
from pycityagent.llm.llm import LLM
|
7
|
-
from pycityagent.
|
7
|
+
from pycityagent.environment import EconomyClient
|
8
8
|
from pycityagent.message import Messager
|
9
9
|
from pycityagent.memory import Memory
|
10
10
|
import logging
|
@@ -102,4 +102,4 @@ class BankAgent(InstitutionAgent):
|
|
102
102
|
else:
|
103
103
|
interest_rate = natural_interest_rate + target_inflation
|
104
104
|
await self.economy_client.update(self._agent_id, 'interest_rate', interest_rate)
|
105
|
-
print("bank forward end")
|
105
|
+
print("bank forward end")
|
@@ -1,10 +1,10 @@
|
|
1
|
-
from .mobility_block import MobilityBlock
|
2
1
|
from .cognition_block import CognitionBlock
|
3
|
-
from .plan_block import PlanBlock
|
4
|
-
from .needs_block import NeedsBlock
|
5
|
-
from .social_block import SocialBlock
|
6
2
|
from .economy_block import EconomyBlock
|
3
|
+
from .mobility_block import MobilityBlock
|
4
|
+
from .needs_block import NeedsBlock
|
7
5
|
from .other_block import OtherBlock
|
6
|
+
from .plan_block import PlanBlock
|
7
|
+
from .social_block import SocialBlock
|
8
8
|
|
9
9
|
__all__ = [
|
10
10
|
"MobilityBlock",
|
@@ -37,6 +37,7 @@ class CognitionBlock(Block):
|
|
37
37
|
super().__init__("CognitionBlock", llm=llm, memory=memory, simulator=simulator)
|
38
38
|
self.top_k = 20
|
39
39
|
self.last_check_time = 0
|
40
|
+
|
40
41
|
async def set_status(self, status):
|
41
42
|
for key in status:
|
42
43
|
await self.memory.status.update(key, status[key])
|
@@ -75,7 +76,9 @@ class CognitionBlock(Block):
|
|
75
76
|
In the following 21 words, I have chosen {emotion_types} to represent your current status:
|
76
77
|
Joy, Distress, Resentment, Pity, Hope, Fear, Satisfaction, Relief, Disappointment, Pride, Admiration, Shame, Reproach, Liking, Disliking, Gratitude, Anger, Gratification, Remorse, Love, Hate.
|
77
78
|
"""
|
78
|
-
incident_str = await self.memory.stream.search(
|
79
|
+
incident_str = await self.memory.stream.search(
|
80
|
+
query=topic, top_k=self.top_k
|
81
|
+
)
|
79
82
|
if incident_str:
|
80
83
|
incident_prompt = "Today, these incidents happened:"
|
81
84
|
incident_prompt += incident_str
|
@@ -110,7 +113,7 @@ class CognitionBlock(Block):
|
|
110
113
|
for retry in range(10):
|
111
114
|
try:
|
112
115
|
_response = await self.llm.atext_request(
|
113
|
-
question_prompt.to_dialog(), timeout=300
|
116
|
+
question_prompt.to_dialog(), timeout=300, response_format={"type": "json_object"}
|
114
117
|
)
|
115
118
|
response = json.loads(extract_json(_response)) # type:ignore
|
116
119
|
evaluation = False
|
@@ -186,7 +189,7 @@ class CognitionBlock(Block):
|
|
186
189
|
for retry in range(10):
|
187
190
|
try:
|
188
191
|
_response = await self.llm.atext_request(
|
189
|
-
question_prompt.to_dialog(), timeout=300
|
192
|
+
question_prompt.to_dialog(), timeout=300, response_format={"type": "json_object"}
|
190
193
|
)
|
191
194
|
response = json.loads(extract_json(_response)) # type:ignore
|
192
195
|
evaluation = False
|
@@ -280,7 +283,7 @@ class CognitionBlock(Block):
|
|
280
283
|
for retry in range(10):
|
281
284
|
try:
|
282
285
|
_response = await self.llm.atext_request(
|
283
|
-
question_prompt.to_dialog(), timeout=300
|
286
|
+
question_prompt.to_dialog(), timeout=300, response_format={"type": "json_object"}
|
284
287
|
)
|
285
288
|
response = json.loads(extract_json(_response)) # type:ignore
|
286
289
|
evaluation = False
|