pycityagent 2.0.0a5__py3-none-any.whl → 2.0.0a6__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 CHANGED
@@ -67,6 +67,7 @@ class Agent(ABC):
67
67
  self._messager = messager
68
68
  self._simulator = simulator
69
69
  self._memory = memory
70
+ self._exp_id = -1
70
71
  self._has_bound_to_simulator = False
71
72
  self._has_bound_to_economy = False
72
73
  self._blocked = False
@@ -113,6 +114,12 @@ class Agent(ABC):
113
114
  """
114
115
  self._memory = memory
115
116
 
117
+ def set_exp_id(self, exp_id: str):
118
+ """
119
+ Set the exp_id of the agent.
120
+ """
121
+ self._exp_id = exp_id
122
+
116
123
  async def _bind_to_simulator(self):
117
124
  """
118
125
  Bind Agent to Simulator
@@ -185,7 +192,7 @@ class Agent(ABC):
185
192
  )
186
193
 
187
194
  @property
188
- def LLM(self):
195
+ def llm(self):
189
196
  """The Agent's LLM"""
190
197
  if self._llm_client is None:
191
198
  raise RuntimeError(
@@ -282,7 +289,7 @@ class Agent(ABC):
282
289
  """通过 Messager 发送消息,附带发送者的 ID"""
283
290
  if self._messager is None:
284
291
  raise RuntimeError("Messager is not set")
285
- topic = f"/agents/{to_agent_id}/chat"
292
+ topic = f"/exps/{self._exp_id}/agents/{to_agent_id}/chat"
286
293
  await self._messager.send_message(topic, message, self._agent_id)
287
294
 
288
295
  @abstractmethod
@@ -10,9 +10,10 @@ from pycityagent.message import Messager
10
10
 
11
11
  @ray.remote
12
12
  class AgentGroup:
13
- def __init__(self, agents: list[Agent], config: dict):
13
+ def __init__(self, agents: list[Agent], config: dict, exp_id: str):
14
14
  self.agents = agents
15
15
  self.config = config
16
+ self.exp_id = exp_id
16
17
  self.messager = Messager(config["simulator_request"]["mqtt"]["server"], config["simulator_request"]["mqtt"]["port"])
17
18
  self.initialized = False
18
19
 
@@ -30,6 +31,7 @@ class AgentGroup:
30
31
  self.economy_client = EconomyClient(config["simulator_request"]["economy"]['server'])
31
32
 
32
33
  for agent in self.agents:
34
+ agent.set_exp_id(self.exp_id)
33
35
  agent.set_llm_client(self.llm)
34
36
  agent.set_simulator(self.simulator)
35
37
  agent.set_economy_client(self.economy_client)
@@ -44,7 +46,7 @@ class AgentGroup:
44
46
  await self.messager.start_listening()
45
47
  for agent in self.agents:
46
48
  agent.set_messager(self.messager)
47
- topic = f"/agents/{agent._agent_id}/chat"
49
+ topic = f"/exps/{self.exp_id}/agents/{agent._agent_id}/chat"
48
50
  await self.messager.subscribe(topic, agent)
49
51
  self.initialized = True
50
52
 
@@ -71,9 +73,8 @@ class AgentGroup:
71
73
  # 添加解码步骤,将bytes转换为str
72
74
  if isinstance(payload, bytes):
73
75
  payload = payload.decode('utf-8')
74
-
75
- # 提取 agent_id(主题格式为 "/agents/{agent_id}/chat"
76
- _, agent_id, _ = topic.strip("/").split("/")
76
+ # 提取 agent_id(主题格式为 "/exps/{exp_id}/agents/{agent_id}/chat")
77
+ _, _, _, agent_id, _ = topic.strip("/").split("/")
77
78
  agent_id = int(agent_id)
78
79
 
79
80
  if agent_id in self.id2agent:
@@ -1,15 +1,13 @@
1
1
  import asyncio
2
2
  import json
3
3
  import logging
4
+ import uuid
4
5
  from datetime import datetime
5
6
  import random
6
7
  from typing import Dict, List, Optional, Callable
7
8
  from mosstool.map._map_util.const import AOI_START_ID
8
9
 
9
- from pycityagent.economy.econ_client import EconomyClient
10
- from pycityagent.environment.simulator import Simulator
11
10
  from pycityagent.memory.memory import Memory
12
- from pycityagent.message.messager import Messager
13
11
 
14
12
  from ..agent import Agent
15
13
  from .interview import InterviewManager
@@ -28,6 +26,7 @@ class AgentSimulation:
28
26
  config: 配置
29
27
  agent_prefix: 智能体名称前缀
30
28
  """
29
+ self.exp_id = uuid.uuid4()
31
30
  self.agent_class = agent_class
32
31
  self.config = config
33
32
  self.agent_prefix = agent_prefix
@@ -83,7 +82,7 @@ class AgentSimulation:
83
82
  # 获取当前组的agents
84
83
  agents = list(self._agents.values())[start_idx:end_idx]
85
84
  group_name = f"{self.agent_prefix}_group_{i}"
86
- group = AgentGroup.remote(agents, self.config)
85
+ group = AgentGroup.remote(agents, self.config, self.exp_id)
87
86
  self._groups[group_name] = group
88
87
 
89
88
  def default_memory_config_func(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycityagent
3
- Version: 2.0.0a5
3
+ Version: 2.0.0a6
4
4
  Summary: LLM-based城市环境agent构建库
5
5
  License: MIT
6
6
  Author: Yuwei Yan
@@ -1,5 +1,5 @@
1
1
  pycityagent/__init__.py,sha256=n56bWkAUEcvjDsb7LcJpaGjlrriSKPnR0yBhwRfEYBA,212
2
- pycityagent/agent.py,sha256=VvNTTw5MLY8XRMdOIgstBmru7v29r7q3QY7f-UjN9Bg,11086
2
+ pycityagent/agent.py,sha256=U1cdyRl_ZURnPLC31uP8auvSa4TWupK_SZ5nuff3Ryk,11263
3
3
  pycityagent/economy/__init__.py,sha256=aonY4WHnx-6EGJ4WKrx4S-2jAkYNLtqUA04jp6q8B7w,75
4
4
  pycityagent/economy/econ_client.py,sha256=qQb_kZneEXGBRaS_y5Jdoi95I8GyjKEsDSC4s6V6R7w,10829
5
5
  pycityagent/environment/__init__.py,sha256=awHxlOud-btWbk0FCS4RmGJ13W84oVCkbGfcrhKqihA,240
@@ -46,9 +46,9 @@ pycityagent/memory/utils.py,sha256=97lkenn-36wgt7uWb3Z39BXdJ5zlEQTQnQBFpoND1gg,8
46
46
  pycityagent/message/__init__.py,sha256=dEigAhYQ8e-suktavjo-Ip-nkEzf659hrFJwoFQ2ljE,54
47
47
  pycityagent/message/messager.py,sha256=Xd02IxSkVtfrC386frB5kiqlDIDhNKuh5pVM4xKIyyw,2463
48
48
  pycityagent/simulation/__init__.py,sha256=SZQzjcGR-zkTDrE81bQuEdKn7yjk4BcZ9m7o1wTc7EE,111
49
- pycityagent/simulation/agentgroup.py,sha256=mHW8ggwG1iQ_-dCL5t_8Nlkp4OnCshdGGKygq9jFZX8,3983
49
+ pycityagent/simulation/agentgroup.py,sha256=G2aRk1d3d5Ja4QPNJagNKz8a_9_JzSmQXqmDrteYkkg,4105
50
50
  pycityagent/simulation/interview.py,sha256=mY4Vpz0vgJo4rrMy3TZnwwM-iVDL6J0LgjOxbEuV27E,1173
51
- pycityagent/simulation/simulation.py,sha256=PcWYx8GqCypqDga9JdHg3sRux5lrGcT8b_hvapjKw34,13177
51
+ pycityagent/simulation/simulation.py,sha256=98_dxWAUNhbVyDQlsGq7SB_QpXF2r8vezVk1C54P6IY,13073
52
52
  pycityagent/simulation/survey/__init__.py,sha256=hFJ0Q1yo4jwKAIXP17sznBSWwm2Lyh3F3W3Lly40wr8,172
53
53
  pycityagent/simulation/survey/manager.py,sha256=DkNrb12Ay7TiGURoyJTFFeUdV1zh6TgRpTmpZOblADw,2158
54
54
  pycityagent/simulation/survey/models.py,sha256=-3EKe-qvkUJ2TH24ow0A_Lc4teGet7pueN2T5mOR_Qc,1308
@@ -65,6 +65,6 @@ pycityagent/workflow/block.py,sha256=IXfarqIax6yVP_DniU6ZsPTT8QA4aIDnvZbwP_MtRaw
65
65
  pycityagent/workflow/prompt.py,sha256=cmzKEmlzjdwg50uwfnTnN_6xNJA8OVjo5fdmcsaTbdU,2886
66
66
  pycityagent/workflow/tool.py,sha256=2VDzBISnx7LASdAou8Zu230j7o2SdK1oBeqHtwDHZy0,6711
67
67
  pycityagent/workflow/trigger.py,sha256=8530YfBbLsdtT1QZSqvuha64NNLVJYXVznlvknz9-xI,5737
68
- pycityagent-2.0.0a5.dist-info/METADATA,sha256=eGx85-Jh_-wtRP3XhlJne7IpW5gpB-4iJrLsuoe9brQ,7614
69
- pycityagent-2.0.0a5.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
70
- pycityagent-2.0.0a5.dist-info/RECORD,,
68
+ pycityagent-2.0.0a6.dist-info/METADATA,sha256=u-2FElVNMV8-kXaAz5V8paLzLs3REC-gP_zO5DL6jkQ,7614
69
+ pycityagent-2.0.0a6.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
70
+ pycityagent-2.0.0a6.dist-info/RECORD,,