pycityagent 2.0.0a22__py3-none-any.whl → 2.0.0a25__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/__init__.py +2 -1
- pycityagent/agent.py +13 -2
- pycityagent/environment/simulator.py +5 -5
- pycityagent/llm/__init__.py +7 -2
- pycityagent/llm/embeddings.py +231 -0
- pycityagent/memory/__init__.py +2 -0
- pycityagent/memory/faiss_query.py +302 -0
- pycityagent/memory/memory.py +131 -137
- pycityagent/simulation/agentgroup.py +42 -25
- pycityagent/simulation/simulation.py +9 -1
- {pycityagent-2.0.0a22.dist-info → pycityagent-2.0.0a25.dist-info}/METADATA +5 -1
- {pycityagent-2.0.0a22.dist-info → pycityagent-2.0.0a25.dist-info}/RECORD +13 -12
- pycityagent/llm/embedding.py +0 -136
- {pycityagent-2.0.0a22.dist-info → pycityagent-2.0.0a25.dist-info}/WHEEL +0 -0
pycityagent/memory/memory.py
CHANGED
@@ -1,21 +1,25 @@
|
|
1
1
|
import asyncio
|
2
2
|
import logging
|
3
|
+
from collections import defaultdict
|
4
|
+
from collections.abc import Callable, Sequence
|
3
5
|
from copy import deepcopy
|
4
6
|
from datetime import datetime
|
5
|
-
from typing import Any, Literal, Optional,
|
6
|
-
from collections.abc import Sequence,Callable
|
7
|
+
from typing import Any, Literal, Optional, Union
|
7
8
|
|
8
9
|
import numpy as np
|
10
|
+
from langchain_core.embeddings import Embeddings
|
9
11
|
from pyparsing import deque
|
10
12
|
|
11
13
|
from ..utils.decorators import lock_decorator
|
12
14
|
from .const import *
|
15
|
+
from .faiss_query import FaissQuery
|
13
16
|
from .profile import ProfileMemory
|
14
17
|
from .self_define import DynamicMemory
|
15
18
|
from .state import StateMemory
|
16
19
|
|
17
20
|
logger = logging.getLogger("pycityagent")
|
18
21
|
|
22
|
+
|
19
23
|
class Memory:
|
20
24
|
"""
|
21
25
|
A class to manage different types of memory (state, profile, dynamic).
|
@@ -33,7 +37,8 @@ class Memory:
|
|
33
37
|
base: Optional[dict[Any, Any]] = None,
|
34
38
|
motion: Optional[dict[Any, Any]] = None,
|
35
39
|
activate_timestamp: bool = False,
|
36
|
-
embedding_model:
|
40
|
+
embedding_model: Optional[Embeddings] = None,
|
41
|
+
faiss_query: Optional[FaissQuery] = None,
|
37
42
|
) -> None:
|
38
43
|
"""
|
39
44
|
Initializes the Memory with optional configuration.
|
@@ -51,20 +56,21 @@ class Memory:
|
|
51
56
|
base (Optional[dict[Any, Any]], optional): base attribute dict from City Simulator.
|
52
57
|
motion (Optional[dict[Any, Any]], optional): motion attribute dict from City Simulator.
|
53
58
|
activate_timestamp (bool): Whether activate timestamp storage in MemoryUnit
|
54
|
-
embedding_model (
|
59
|
+
embedding_model (Embeddings): The embedding model for memory search.
|
60
|
+
faiss_query (FaissQuery): The faiss_query of the agent. Defaults to None.
|
55
61
|
"""
|
56
62
|
self.watchers: dict[str, list[Callable]] = {}
|
57
63
|
self._lock = asyncio.Lock()
|
58
|
-
self.
|
59
|
-
|
60
|
-
# 初始化embedding存储
|
61
|
-
self._embeddings = {"state": {}, "profile": {}, "dynamic": {}}
|
64
|
+
self._agent_id: int = -1
|
65
|
+
self._embedding_model = embedding_model
|
62
66
|
|
63
67
|
_dynamic_config: dict[Any, Any] = {}
|
64
68
|
_state_config: dict[Any, Any] = {}
|
65
69
|
_profile_config: dict[Any, Any] = {}
|
66
70
|
# 记录哪些字段需要embedding
|
67
71
|
self._embedding_fields: dict[str, bool] = {}
|
72
|
+
self._embedding_field_to_doc_id: dict[Any, str] = defaultdict(str)
|
73
|
+
self._faiss_query = faiss_query
|
68
74
|
|
69
75
|
if config is not None:
|
70
76
|
for k, v in config.items():
|
@@ -135,8 +141,55 @@ class Memory:
|
|
135
141
|
self._profile = ProfileMemory(
|
136
142
|
msg=_profile_config, activate_timestamp=activate_timestamp
|
137
143
|
)
|
138
|
-
self.memories = [] # 存储记忆内容
|
139
|
-
self.embeddings = [] # 存储记忆的向量表示
|
144
|
+
# self.memories = [] # 存储记忆内容
|
145
|
+
# self.embeddings = [] # 存储记忆的向量表示
|
146
|
+
|
147
|
+
def set_embedding_model(
|
148
|
+
self,
|
149
|
+
embedding_model: Embeddings,
|
150
|
+
):
|
151
|
+
self._embedding_model = embedding_model
|
152
|
+
|
153
|
+
@property
|
154
|
+
def embedding_model(
|
155
|
+
self,
|
156
|
+
):
|
157
|
+
if self._embedding_model is None:
|
158
|
+
raise RuntimeError(
|
159
|
+
f"embedding_model before assignment, please `set_embedding_model` first!"
|
160
|
+
)
|
161
|
+
return self._embedding_model
|
162
|
+
|
163
|
+
def set_faiss_query(self, faiss_query: FaissQuery):
|
164
|
+
"""
|
165
|
+
Set the FaissQuery of the agent.
|
166
|
+
"""
|
167
|
+
self._faiss_query = faiss_query
|
168
|
+
|
169
|
+
@property
|
170
|
+
def agent_id(
|
171
|
+
self,
|
172
|
+
):
|
173
|
+
if self._agent_id < 0:
|
174
|
+
raise RuntimeError(
|
175
|
+
f"agent_id before assignment, please `set_agent_id` first!"
|
176
|
+
)
|
177
|
+
return self._agent_id
|
178
|
+
|
179
|
+
def set_agent_id(self, agent_id: int):
|
180
|
+
"""
|
181
|
+
Set the FaissQuery of the agent.
|
182
|
+
"""
|
183
|
+
self._agent_id = agent_id
|
184
|
+
|
185
|
+
@property
|
186
|
+
def faiss_query(self) -> FaissQuery:
|
187
|
+
"""FaissQuery"""
|
188
|
+
if self._faiss_query is None:
|
189
|
+
raise RuntimeError(
|
190
|
+
f"FaissQuery access before assignment, please `set_faiss_query` first!"
|
191
|
+
)
|
192
|
+
return self._faiss_query
|
140
193
|
|
141
194
|
@lock_decorator
|
142
195
|
async def get(
|
@@ -192,11 +245,23 @@ class Memory:
|
|
192
245
|
if mode == "replace":
|
193
246
|
await _mem.update(key, value, store_snapshot)
|
194
247
|
# 如果字段需要embedding,则更新embedding
|
195
|
-
if self.
|
248
|
+
if self._embedding_fields.get(key, False) and self.embedding_model:
|
196
249
|
memory_type = self._get_memory_type(_mem)
|
197
|
-
|
198
|
-
|
250
|
+
# 覆盖更新删除原vector
|
251
|
+
orig_doc_id = self._embedding_field_to_doc_id[key]
|
252
|
+
if orig_doc_id:
|
253
|
+
await self.faiss_query.delete_documents(
|
254
|
+
to_delete_ids=[orig_doc_id],
|
255
|
+
)
|
256
|
+
doc_ids: list[str] = await self.faiss_query.add_documents(
|
257
|
+
agent_id=self.agent_id,
|
258
|
+
documents=f"{key}: {str(value)}",
|
259
|
+
extra_tags={
|
260
|
+
"type": memory_type,
|
261
|
+
"key": key,
|
262
|
+
},
|
199
263
|
)
|
264
|
+
self._embedding_field_to_doc_id[key] = doc_ids[0]
|
200
265
|
if key in self.watchers:
|
201
266
|
for callback in self.watchers[key]:
|
202
267
|
asyncio.create_task(callback())
|
@@ -214,13 +279,17 @@ class Memory:
|
|
214
279
|
f"Type of {type(original_value)} does not support mode `merge`, using `replace` instead!"
|
215
280
|
)
|
216
281
|
await _mem.update(key, value, store_snapshot)
|
217
|
-
if self.
|
282
|
+
if self._embedding_fields.get(key, False) and self.embedding_model:
|
218
283
|
memory_type = self._get_memory_type(_mem)
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
284
|
+
doc_ids = await self.faiss_query.add_documents(
|
285
|
+
agent_id=self.agent_id,
|
286
|
+
documents=f"{key}: {str(original_value)}",
|
287
|
+
extra_tags={
|
288
|
+
"type": memory_type,
|
289
|
+
"key": key,
|
290
|
+
},
|
223
291
|
)
|
292
|
+
self._embedding_field_to_doc_id[key] = doc_ids[0]
|
224
293
|
if key in self.watchers:
|
225
294
|
for callback in self.watchers[key]:
|
226
295
|
asyncio.create_task(callback())
|
@@ -240,68 +309,6 @@ class Memory:
|
|
240
309
|
else:
|
241
310
|
return "dynamic"
|
242
311
|
|
243
|
-
async def _generate_embedding(self, text: str) -> np.ndarray:
|
244
|
-
"""生成文本的向量表示
|
245
|
-
|
246
|
-
Args:
|
247
|
-
text: 输入文本
|
248
|
-
|
249
|
-
Returns:
|
250
|
-
np.ndarray: 文本的向量表示
|
251
|
-
|
252
|
-
Raises:
|
253
|
-
ValueError: 如果embedding_model未初始化
|
254
|
-
"""
|
255
|
-
if not self.embedding_model:
|
256
|
-
raise RuntimeError("Embedding model not initialized")
|
257
|
-
|
258
|
-
return await self.embedding_model.embed(text)
|
259
|
-
|
260
|
-
async def search(self, query: str, top_k: int = 3) -> str:
|
261
|
-
"""搜索相关记忆
|
262
|
-
|
263
|
-
Args:
|
264
|
-
query: 查询文本
|
265
|
-
top_k: 返回最相关的记忆数量
|
266
|
-
|
267
|
-
Returns:
|
268
|
-
str: 格式化的相关记忆文本
|
269
|
-
"""
|
270
|
-
if not self.embedding_model:
|
271
|
-
return "Embedding model not initialized"
|
272
|
-
|
273
|
-
query_embedding = await self._generate_embedding(query)
|
274
|
-
all_results = []
|
275
|
-
|
276
|
-
# 搜索所有记忆类型中启用了embedding的字段
|
277
|
-
for memory_type, embeddings in self._embeddings.items():
|
278
|
-
for key, embedding in embeddings.items():
|
279
|
-
similarity = self._cosine_similarity(query_embedding, embedding)
|
280
|
-
value = await self.get(key)
|
281
|
-
|
282
|
-
all_results.append(
|
283
|
-
{
|
284
|
-
"type": memory_type,
|
285
|
-
"key": key,
|
286
|
-
"content": f"{key}: {str(value)}",
|
287
|
-
"similarity": similarity,
|
288
|
-
}
|
289
|
-
)
|
290
|
-
|
291
|
-
# 按相似度排序
|
292
|
-
all_results.sort(key=lambda x: x["similarity"], reverse=True)
|
293
|
-
top_results = all_results[:top_k]
|
294
|
-
|
295
|
-
# 格式化输出
|
296
|
-
formatted_results = []
|
297
|
-
for result in top_results:
|
298
|
-
formatted_results.append(
|
299
|
-
f"- [{result['type']}] {result['content']} "
|
300
|
-
f"(相关度: {result['similarity']:.2f})"
|
301
|
-
)
|
302
|
-
|
303
|
-
return "\n".join(formatted_results)
|
304
|
-
|
305
312
|
async def update_batch(
|
306
313
|
self,
|
307
314
|
content: Union[dict, Sequence[tuple[Any, Any]]],
|
@@ -388,67 +395,54 @@ class Memory:
|
|
388
395
|
if _snapshot:
|
389
396
|
await _mem.load(snapshots=_snapshot, reset_memory=reset_memory)
|
390
397
|
|
398
|
+
# async def add(self, content: str, metadata: Optional[dict] = None) -> None:
|
399
|
+
# """添加新的记忆
|
400
|
+
|
401
|
+
# Args:
|
402
|
+
# content: 记忆内容
|
403
|
+
# metadata: 相关元数据,如时间、地点等
|
404
|
+
# """
|
405
|
+
# embedding = await self.embedding_model.aembed_query(content)
|
406
|
+
# self.memories.append(
|
407
|
+
# {
|
408
|
+
# "content": content,
|
409
|
+
# "metadata": metadata or {},
|
410
|
+
# "timestamp": datetime.now(),
|
411
|
+
# "embedding": embedding,
|
412
|
+
# }
|
413
|
+
# )
|
414
|
+
# self.embeddings.append(embedding)
|
415
|
+
|
391
416
|
@lock_decorator
|
392
|
-
async def
|
393
|
-
self,
|
394
|
-
|
395
|
-
|
396
|
-
top_k: Optional[int] = None,
|
397
|
-
mode: Union[Literal["read only"], Literal["read and write"]] = "read only",
|
398
|
-
preserve_order: bool = True,
|
399
|
-
) -> Any:
|
400
|
-
"""
|
401
|
-
Retrieves the top-k items from the memory based on the given key and metric.
|
417
|
+
async def search(
|
418
|
+
self, query: str, top_k: int = 3, filter: Optional[dict] = None
|
419
|
+
) -> str:
|
420
|
+
"""搜索相关记忆
|
402
421
|
|
403
422
|
Args:
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
mode (Union[Literal["read only"], Literal["read and write"]], optional): Access mode for the item. Defaults to "read only".
|
408
|
-
preserve_order (bool): Whether preserve original order in output values.
|
423
|
+
query: 查询文本
|
424
|
+
top_k: 返回最相关的记忆数量
|
425
|
+
filter (dict, optional): 记忆的筛选条件,如 {"type":"dynamic", "key":"self_define_1",},默认为空
|
409
426
|
|
410
427
|
Returns:
|
411
|
-
|
412
|
-
|
413
|
-
Raises:
|
414
|
-
ValueError: If an invalid mode is provided.
|
415
|
-
KeyError: If the key is not found in any of the memory sections.
|
416
|
-
"""
|
417
|
-
if mode == "read only":
|
418
|
-
process_func = deepcopy
|
419
|
-
elif mode == "read and write":
|
420
|
-
process_func = lambda x: x
|
421
|
-
else:
|
422
|
-
raise ValueError(f"Invalid get mode `{mode}`!")
|
423
|
-
for _mem in [self._state, self._profile, self._dynamic]:
|
424
|
-
try:
|
425
|
-
value = await _mem.get_top_k(key, metric, top_k, preserve_order)
|
426
|
-
return process_func(value)
|
427
|
-
except KeyError as e:
|
428
|
-
continue
|
429
|
-
raise KeyError(f"No attribute `{key}` in memories!")
|
430
|
-
|
431
|
-
async def add(self, content: str, metadata: Optional[dict] = None) -> None:
|
432
|
-
"""添加新的记忆
|
433
|
-
|
434
|
-
Args:
|
435
|
-
content: 记忆内容
|
436
|
-
metadata: 相关元数据,如时间、地点等
|
428
|
+
str: 格式化的相关记忆文本
|
437
429
|
"""
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
430
|
+
if not self._embedding_model:
|
431
|
+
return "Embedding model not initialized"
|
432
|
+
top_results: list[tuple[str, float, dict]] = (
|
433
|
+
await self.faiss_query.similarity_search( # type:ignore
|
434
|
+
query=query,
|
435
|
+
agent_id=self.agent_id,
|
436
|
+
k=top_k,
|
437
|
+
return_score_type="similarity_score",
|
438
|
+
filter=filter,
|
439
|
+
)
|
446
440
|
)
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
return
|
441
|
+
# 格式化输出
|
442
|
+
formatted_results = []
|
443
|
+
for content, score, metadata in top_results:
|
444
|
+
formatted_results.append(
|
445
|
+
f"- [{metadata['type']}] {content} " f"(相关度: {score:.2f})"
|
446
|
+
)
|
447
|
+
|
448
|
+
return "\n".join(formatted_results)
|
@@ -10,12 +10,14 @@ from uuid import UUID
|
|
10
10
|
|
11
11
|
import fastavro
|
12
12
|
import ray
|
13
|
+
from langchain_core.embeddings import Embeddings
|
13
14
|
|
14
15
|
from ..agent import Agent, CitizenAgent, InstitutionAgent
|
15
16
|
from ..economy.econ_client import EconomyClient
|
16
17
|
from ..environment.simulator import Simulator
|
17
18
|
from ..llm.llm import LLM
|
18
19
|
from ..llm.llmconfig import LLMConfig
|
20
|
+
from ..memory import FaissQuery
|
19
21
|
from ..message import Messager
|
20
22
|
from ..metrics import MlflowClient
|
21
23
|
from ..utils import (DIALOG_SCHEMA, INSTITUTION_STATUS_SCHEMA, PROFILE_SCHEMA,
|
@@ -37,6 +39,7 @@ class AgentGroup:
|
|
37
39
|
enable_pgsql: bool,
|
38
40
|
pgsql_writer: ray.ObjectRef,
|
39
41
|
mlflow_run_id: str,
|
42
|
+
embedding_model: Embeddings,
|
40
43
|
logging_level: int,
|
41
44
|
):
|
42
45
|
logger.setLevel(logging_level)
|
@@ -46,6 +49,7 @@ class AgentGroup:
|
|
46
49
|
self.exp_id = exp_id
|
47
50
|
self.enable_avro = enable_avro
|
48
51
|
self.enable_pgsql = enable_pgsql
|
52
|
+
self.embedding_model = embedding_model
|
49
53
|
if enable_avro:
|
50
54
|
self.avro_path = avro_path / f"{self._uuid}"
|
51
55
|
self.avro_path.mkdir(parents=True, exist_ok=True)
|
@@ -99,6 +103,13 @@ class AgentGroup:
|
|
99
103
|
else:
|
100
104
|
self.mlflow_client = None
|
101
105
|
|
106
|
+
# set FaissQuery
|
107
|
+
if self.embedding_model is not None:
|
108
|
+
self.faiss_query = FaissQuery(
|
109
|
+
embeddings=self.embedding_model,
|
110
|
+
)
|
111
|
+
else:
|
112
|
+
self.faiss_query = None
|
102
113
|
for agent in self.agents:
|
103
114
|
agent.set_exp_id(self.exp_id) # type: ignore
|
104
115
|
agent.set_llm_client(self.llm)
|
@@ -112,6 +123,12 @@ class AgentGroup:
|
|
112
123
|
agent.set_avro_file(self.avro_file) # type: ignore
|
113
124
|
if self.enable_pgsql:
|
114
125
|
agent.set_pgsql_writer(self._pgsql_writer)
|
126
|
+
# set memory.faiss_query
|
127
|
+
if self.faiss_query is not None:
|
128
|
+
agent.memory.set_faiss_query(self.faiss_query)
|
129
|
+
# set memory.embedding model
|
130
|
+
if self.embedding_model is not None:
|
131
|
+
agent.memory.set_embedding_model(self.embedding_model)
|
115
132
|
|
116
133
|
async def init_agents(self):
|
117
134
|
logger.debug(f"-----Initializing Agents in AgentGroup {self._uuid} ...")
|
@@ -376,32 +393,32 @@ class AgentGroup:
|
|
376
393
|
"created_at": _date_time,
|
377
394
|
}
|
378
395
|
_statuses_time_list.append((_status_dict, _date_time))
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
396
|
+
to_update_statues: list[tuple] = []
|
397
|
+
for _status_dict, _ in _statuses_time_list:
|
398
|
+
BASIC_KEYS = [
|
399
|
+
"id",
|
400
|
+
"day",
|
401
|
+
"t",
|
402
|
+
"lng",
|
403
|
+
"lat",
|
404
|
+
"parent_id",
|
405
|
+
"action",
|
406
|
+
"created_at",
|
407
|
+
]
|
408
|
+
_data = [_status_dict[k] for k in BASIC_KEYS if k != "created_at"]
|
409
|
+
_other_dict = json.dumps(
|
410
|
+
{k: v for k, v in _status_dict.items() if k not in BASIC_KEYS}
|
411
|
+
)
|
412
|
+
_data.append(_other_dict)
|
413
|
+
_data.append(_status_dict["created_at"])
|
414
|
+
to_update_statues.append(tuple(_data))
|
415
|
+
if self._last_asyncio_pg_task is not None:
|
416
|
+
await self._last_asyncio_pg_task
|
417
|
+
self._last_asyncio_pg_task = (
|
418
|
+
self._pgsql_writer.async_write_status.remote( # type:ignore
|
419
|
+
to_update_statues
|
420
|
+
)
|
403
421
|
)
|
404
|
-
)
|
405
422
|
|
406
423
|
async def step(self):
|
407
424
|
if not self.initialized:
|
@@ -14,11 +14,13 @@ from typing import Any, Optional, Union
|
|
14
14
|
import pycityproto.city.economy.v2.economy_pb2 as economyv2
|
15
15
|
import ray
|
16
16
|
import yaml
|
17
|
+
from langchain_core.embeddings import Embeddings
|
17
18
|
from mosstool.map._map_util.const import AOI_START_ID
|
18
19
|
|
19
20
|
from ..agent import Agent, InstitutionAgent
|
20
21
|
from ..environment.simulator import Simulator
|
21
|
-
from ..
|
22
|
+
from ..llm import SimpleEmbedding
|
23
|
+
from ..memory import FaissQuery, Memory
|
22
24
|
from ..message.messager import Messager
|
23
25
|
from ..metrics import init_mlflow_connection
|
24
26
|
from ..survey import Survey
|
@@ -76,6 +78,8 @@ class AgentSimulation:
|
|
76
78
|
|
77
79
|
# storage
|
78
80
|
_storage_config: dict[str, Any] = config.get("storage", {})
|
81
|
+
if _storage_config is None:
|
82
|
+
_storage_config = {}
|
79
83
|
# avro
|
80
84
|
_avro_config: dict[str, Any] = _storage_config.get("avro", {})
|
81
85
|
self._enable_avro = _avro_config.get("enabled", False)
|
@@ -164,6 +168,7 @@ class AgentSimulation:
|
|
164
168
|
enable_pgsql: bool,
|
165
169
|
pgsql_writer: ray.ObjectRef,
|
166
170
|
mlflow_run_id: str = None, # type: ignore
|
171
|
+
embedding_model: Embeddings = None, # type: ignore
|
167
172
|
logging_level: int = logging.WARNING,
|
168
173
|
):
|
169
174
|
"""创建远程组"""
|
@@ -177,6 +182,7 @@ class AgentSimulation:
|
|
177
182
|
enable_pgsql,
|
178
183
|
pgsql_writer,
|
179
184
|
mlflow_run_id,
|
185
|
+
embedding_model,
|
180
186
|
logging_level,
|
181
187
|
)
|
182
188
|
return group_name, group, agents
|
@@ -186,6 +192,7 @@ class AgentSimulation:
|
|
186
192
|
agent_count: Union[int, list[int]],
|
187
193
|
group_size: int = 1000,
|
188
194
|
pg_sql_writers: int = 32,
|
195
|
+
embedding_model: Embeddings = SimpleEmbedding(),
|
189
196
|
memory_config_func: Optional[Union[Callable, list[Callable]]] = None,
|
190
197
|
) -> None:
|
191
198
|
"""初始化智能体
|
@@ -305,6 +312,7 @@ class AgentSimulation:
|
|
305
312
|
self.enable_pgsql,
|
306
313
|
_workers[i % _num_workers], # type:ignore
|
307
314
|
mlflow_run_id, # type:ignore
|
315
|
+
embedding_model,
|
308
316
|
self.logging_level,
|
309
317
|
)
|
310
318
|
creation_tasks.append((group_name, group, agents))
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: pycityagent
|
3
|
-
Version: 2.0.
|
3
|
+
Version: 2.0.0a25
|
4
4
|
Summary: LLM-based城市环境agent构建库
|
5
5
|
License: MIT
|
6
6
|
Author: Yuwei Yan
|
@@ -20,10 +20,12 @@ Requires-Dist: aiohttp (==3.10.10)
|
|
20
20
|
Requires-Dist: aiomqtt (>=2.3.0,<3.0.0)
|
21
21
|
Requires-Dist: citystreetview (==1.2.4)
|
22
22
|
Requires-Dist: dashscope (==1.14.1)
|
23
|
+
Requires-Dist: faiss-cpu (>=1.9.0.post1,<2.0.0)
|
23
24
|
Requires-Dist: fastavro (>=1.10.0,<2.0.0)
|
24
25
|
Requires-Dist: geojson (==3.1.0)
|
25
26
|
Requires-Dist: gradio (>=5.7.1,<6.0.0)
|
26
27
|
Requires-Dist: grpcio (==1.67.1)
|
28
|
+
Requires-Dist: langchain-community (>=0.3.13,<0.4.0)
|
27
29
|
Requires-Dist: langchain-core (>=0.3.28,<0.4.0)
|
28
30
|
Requires-Dist: matplotlib (==3.8.3)
|
29
31
|
Requires-Dist: mlflow (>=2.19.0,<3.0.0)
|
@@ -40,6 +42,8 @@ Requires-Dist: pycityproto (>=2.1.5,<3.0.0)
|
|
40
42
|
Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
|
41
43
|
Requires-Dist: ray (>=2.40.0,<3.0.0)
|
42
44
|
Requires-Dist: sidecar (==0.7.0)
|
45
|
+
Requires-Dist: torch (>=2.5.1,<3.0.0)
|
46
|
+
Requires-Dist: transformers (>=4.47.1,<5.0.0)
|
43
47
|
Requires-Dist: zhipuai (>=2.1.5.20230904,<3.0.0.0)
|
44
48
|
Description-Content-Type: text/markdown
|
45
49
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
pycityagent/__init__.py,sha256=
|
2
|
-
pycityagent/agent.py,sha256=
|
1
|
+
pycityagent/__init__.py,sha256=fv0mzNGbHBF6m550yYqnuUpB8iQPWS-7EatYRK7DO4s,693
|
2
|
+
pycityagent/agent.py,sha256=l8Oa95_K5JBWKzvZmbQe_QM_E_vaG-YstuuR55kgC6Y,29005
|
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
|
@@ -21,7 +21,7 @@ pycityagent/environment/sim/person_service.py,sha256=5r1F2Itn7dKJ2U4hSLovrk5p4qy
|
|
21
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
23
|
pycityagent/environment/sim/social_service.py,sha256=9EFJAwVdUuUQkNkFRn9qZRDfD1brh2fqkvasnXUEBhQ,2014
|
24
|
-
pycityagent/environment/simulator.py,sha256=
|
24
|
+
pycityagent/environment/simulator.py,sha256=Vm8Rvczv20ETpAWhCYyxbnN25uoRyAv6DX7WoavjEVU,12446
|
25
25
|
pycityagent/environment/utils/__init__.py,sha256=1m4Q1EfGvNpUsa1bgQzzCyWhfkpElnskNImjjFD3Znc,237
|
26
26
|
pycityagent/environment/utils/base64.py,sha256=hoREzQo3FXMN79pqQLO2jgsDEvudciomyKii7MWljAM,374
|
27
27
|
pycityagent/environment/utils/const.py,sha256=3RMNy7_bE7-23K90j9DFW_tWEzu8s7hSTgKbV-3BFl4,5327
|
@@ -30,14 +30,15 @@ pycityagent/environment/utils/grpc.py,sha256=6EJwKXXktIWb1NcUiJzIRmfrY0S03QAXXGc
|
|
30
30
|
pycityagent/environment/utils/map_utils.py,sha256=lYOEoCFFK6-e9N5txLMMq4HUlxMqc8Uw1YrGW5oJmgg,5749
|
31
31
|
pycityagent/environment/utils/port.py,sha256=3OM6kSUt3PxvDUOlgyiendBtETaWU8Mzk_8H0TzTmYg,295
|
32
32
|
pycityagent/environment/utils/protobuf.py,sha256=0BsM_G7x2B_6DMIBHe9bjVuQDOXUytNRQ03g9e05F3c,1170
|
33
|
-
pycityagent/llm/__init__.py,sha256=
|
34
|
-
pycityagent/llm/
|
33
|
+
pycityagent/llm/__init__.py,sha256=iWs6FLgrbRVIiqOf4ILS89gkVCTvS7HFC3vG-MWuyko,205
|
34
|
+
pycityagent/llm/embeddings.py,sha256=Nhf_tUIlaYJAZ93wW2QTCtS1wq7e8fUgdn2JketEAuQ,7600
|
35
35
|
pycityagent/llm/llm.py,sha256=vJaaGqVuyV-GlBxrnvGKZnMDlxeTT_sGUTdxz5tYwEE,15141
|
36
36
|
pycityagent/llm/llmconfig.py,sha256=4Ylf4OFSBEFy8jrOneeX0HvPhWEaF5jGvy1HkXK08Ro,436
|
37
37
|
pycityagent/llm/utils.py,sha256=hoNPhvomb1u6lhFX0GctFipw74hVKb7bvUBDqwBzBYw,160
|
38
|
-
pycityagent/memory/__init__.py,sha256=
|
38
|
+
pycityagent/memory/__init__.py,sha256=_Vfdo1HcLWsuuz34_i8e91nnLVYADpMlHHSVaB3xgIk,297
|
39
39
|
pycityagent/memory/const.py,sha256=6zpJPJXWoH9-yf4RARYYff586agCoud9BRn7sPERB1g,932
|
40
|
-
pycityagent/memory/
|
40
|
+
pycityagent/memory/faiss_query.py,sha256=Z0JS4udyPYCIzHMq464QtHscnswu35gh9fQptikAwkQ,12976
|
41
|
+
pycityagent/memory/memory.py,sha256=UBh4yANNHDzYZwrsvyX4ZMSHXINbu1U6g0HLNCOOCk8,17883
|
41
42
|
pycityagent/memory/memory_base.py,sha256=QG_j3BxZvkadFEeE3uBR_kjl_xcXD1aHUVs8GEF3d6w,5654
|
42
43
|
pycityagent/memory/profile.py,sha256=q8ZS9IBmHCg_X1GONUvXK85P6tCepTKQgXKuvuXYNXw,5203
|
43
44
|
pycityagent/memory/self_define.py,sha256=vpZ6CIxR2grNXEIOScdpsSc59FBg0mOKelwQuTElbtQ,5200
|
@@ -49,8 +50,8 @@ pycityagent/metrics/__init__.py,sha256=X08PaBbGVAd7_PRGLREXWxaqm7nS82WBQpD1zvQzc
|
|
49
50
|
pycityagent/metrics/mlflow_client.py,sha256=g_tHxWkWTDijtbGL74-HmiYzWVKb1y8-w12QrY9jL30,4449
|
50
51
|
pycityagent/metrics/utils/const.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
51
52
|
pycityagent/simulation/__init__.py,sha256=P5czbcg2d8S0nbbnsQXFIhwzO4CennAhZM8OmKvAeYw,194
|
52
|
-
pycityagent/simulation/agentgroup.py,sha256=
|
53
|
-
pycityagent/simulation/simulation.py,sha256=
|
53
|
+
pycityagent/simulation/agentgroup.py,sha256=r8arCAQkKMhv3yr35XsYJL-MfG6o6rWwHItBmxfDtA4,20589
|
54
|
+
pycityagent/simulation/simulation.py,sha256=9kkdgXSEOAN8wiewVFyORksti4IdVNU0opObV6ZYa9k,23344
|
54
55
|
pycityagent/simulation/storage/pg.py,sha256=Ws04mUgRcbbvWi_eQm3PXYa6w7AQUbDPWhSU7HFtsD8,6026
|
55
56
|
pycityagent/survey/__init__.py,sha256=rxwou8U9KeFSP7rMzXtmtp2fVFZxK4Trzi-psx9LPIs,153
|
56
57
|
pycityagent/survey/manager.py,sha256=S5IkwTdelsdtZETChRcfCEczzwSrry_Fly9MY4s3rbk,1681
|
@@ -69,6 +70,6 @@ pycityagent/workflow/block.py,sha256=l-z9iJo9_USZQRyj4TLMfihK0-tnNDG0a6jVk9WhG0o
|
|
69
70
|
pycityagent/workflow/prompt.py,sha256=6jI0Rq54JLv3-IXqZLYug62vse10wTI83xvf4ZX42nk,2929
|
70
71
|
pycityagent/workflow/tool.py,sha256=xADxhNgVsjNiMxlhdwn3xGUstFOkLEG8P67ez8VmwSI,8555
|
71
72
|
pycityagent/workflow/trigger.py,sha256=Df-MOBEDWBbM-v0dFLQLXteLsipymT4n8vqexmK2GiQ,5643
|
72
|
-
pycityagent-2.0.
|
73
|
-
pycityagent-2.0.
|
74
|
-
pycityagent-2.0.
|
73
|
+
pycityagent-2.0.0a25.dist-info/METADATA,sha256=lB0qL357khfixTBH-M-cX2-FxCGhsD3IuUyPqVY07uI,8033
|
74
|
+
pycityagent-2.0.0a25.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
75
|
+
pycityagent-2.0.0a25.dist-info/RECORD,,
|