mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-15 11:02:36 +02:00
add temp_storage_path
This commit is contained in:
parent
11266747d7
commit
84d37954b7
13 changed files with 66 additions and 27 deletions
|
|
@ -1,7 +1,11 @@
|
|||
## Stanford Town Game
|
||||
|
||||
### Pre-Description
|
||||
The path configured in `examples/st_game/utils/const.py` is the storage path of the current project. In order to facilitate GA(generative_agents)'s frontend docking data (to avoid changing its code), you can change the path under `const.py` like beflow
|
||||
The path configured in `examples/st_game/utils/const.py` is the storage path of the current project. In order to facilitate GA( [generative_agents](https://github.com/joonspk-research/generative_agents) )'s frontend docking data (to avoid changing its code), you can set the value `temp_storage_path` to `temp_storage` of `generative_agents` when start `run_st_game.py`. like
|
||||
|
||||
`python3 run_st_game.py --temp_storage_path path/to/ga/temp_storage xxx`
|
||||
|
||||
Or change the path under `const.py` like beflow
|
||||
|
||||
```
|
||||
STORAGE_PATH = ROOT_PATH.joinpath("storage")
|
||||
|
|
@ -19,7 +23,9 @@ ### Backend service startup
|
|||
`idea` is the user's voice to the first Agent, and it is disseminated through this voice to see whether the final multi-agents achieve the goal of hosting or participating in the event.
|
||||
|
||||
### Frontend service startup
|
||||
Enter `generative_agents/environment/frontend_server` and use `python manage.py runserver` to start the front-end service.
|
||||
Enter project folder `generative_agents`
|
||||
|
||||
Enter `environment/frontend_server` and use `python3 manage.py runserver` to start the front-end service.
|
||||
Visit `http://localhost:8000/simulator_home` to enter the current simulation interface.
|
||||
|
||||
## Appreciation
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
## Stanford Town Game
|
||||
|
||||
### 前置
|
||||
`examples/st_game/utils/const.py`配置的路径为当前项目的存储路径,为了方便GA(generative_agents)的前端对接数据(避免改动它那块的代码),可将`const.py`下的
|
||||
`examples/st_game/utils/const.py`配置的路径为当前项目的存储路径,为了方便GA( [generative_agents](https://github.com/joonspk-research/generative_agents) )的前端对接数据(避免改动它那块的代码),可在启动`run_st_game.py`加上`temp_storage_path`指向`generative_agents`对应的`temp_storage`路径。比如
|
||||
|
||||
`python3 run_st_game.py --temp_storage_path path/to/ga/temp_storage xxx`
|
||||
|
||||
或将`const.py`下的
|
||||
|
||||
```
|
||||
STORAGE_PATH = ROOT_PATH.joinpath("storage")
|
||||
|
|
@ -18,7 +22,9 @@ ### 后端服务启动
|
|||
`idea`为用户给第一个Agent的用户心声,并通过这个心声进行传播,看最后多智能体是否达到举办、参加活动的目标。
|
||||
|
||||
### 前端服务启动
|
||||
进入`generative_agents/environment/frontend_server`,使用`python manage.py runserver`启动前端服务。
|
||||
进入`generative_agents`项目目录
|
||||
|
||||
进入`environment/frontend_server`,使用`python3 manage.py runserver`启动前端服务。
|
||||
访问`http://localhost:8000/simulator_home` 进入当前的仿真界面。
|
||||
|
||||
## Appreciation
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ class GenActionArena(STAction):
|
|||
prompt_input = create_prompt_input(role, act_desp, act_world, act_sector)
|
||||
prompt = self.generate_prompt_with_tmpl_filename(prompt_input, prompt_template)
|
||||
self.fail_default_resp = self._func_fail_default_resp()
|
||||
print('prompt ', prompt)
|
||||
print("prompt ", prompt)
|
||||
output = await self._run_gpt35_max_tokens(prompt, max_tokens=15)
|
||||
logger.info(f"Role: {role.name} Action: {self.cls_name} output: {output}")
|
||||
return output
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class STAction(Action):
|
|||
|
||||
async def _aask(self, prompt: str) -> str:
|
||||
return await self.llm.aask(prompt)
|
||||
|
||||
|
||||
async def _run_gpt35_max_tokens(self, prompt: str, max_tokens: int = 50, retry: int = 3):
|
||||
for idx in range(retry):
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ class AgentMemory(Memory):
|
|||
poignancy=poignancy,
|
||||
keywords=keywords,
|
||||
filling=filling,
|
||||
cause_by=cause_by
|
||||
cause_by=cause_by,
|
||||
)
|
||||
|
||||
keywords = [i.lower() for i in keywords]
|
||||
|
|
@ -267,7 +267,7 @@ class AgentMemory(Memory):
|
|||
embedding_key=embedding_pair[0],
|
||||
poignancy=poignancy,
|
||||
keywords=keywords,
|
||||
filling=filling
|
||||
filling=filling,
|
||||
)
|
||||
|
||||
keywords = [i.lower() for i in keywords]
|
||||
|
|
@ -317,7 +317,7 @@ class AgentMemory(Memory):
|
|||
embedding_key=embedding_pair[0],
|
||||
poignancy=poignancy,
|
||||
keywords=keywords,
|
||||
filling=filling
|
||||
filling=filling,
|
||||
)
|
||||
|
||||
keywords = [i.lower() for i in keywords]
|
||||
|
|
|
|||
|
|
@ -608,7 +608,9 @@ async def _determine_action(role: "STRole"):
|
|||
# We decompose if the next action is longer than an hour, and fits the
|
||||
# criteria described in determine_decomp.
|
||||
if determine_decomp(act_desp, act_dura):
|
||||
role.scratch.f_daily_schedule[curr_index : curr_index + 1] = await TaskDecomp().run(role, act_desp, act_dura)
|
||||
role.scratch.f_daily_schedule[curr_index : curr_index + 1] = await TaskDecomp().run(
|
||||
role, act_desp, act_dura
|
||||
)
|
||||
if curr_index_60 + 1 < len(role.scratch.f_daily_schedule):
|
||||
act_desp, act_dura = role.scratch.f_daily_schedule[curr_index_60 + 1]
|
||||
if act_dura >= 60:
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
# @Desc : entry of Stanford Town(ST/st) game
|
||||
|
||||
import asyncio
|
||||
from typing import Optional
|
||||
|
||||
import fire
|
||||
|
||||
|
|
@ -18,7 +19,9 @@ from examples.st_game.utils.utils import copy_folder
|
|||
from metagpt.logs import logger
|
||||
|
||||
|
||||
async def startup(idea: str, fork_sim_code: str, sim_code: str, investment: float = 30.0, n_round: int = 500):
|
||||
async def startup(
|
||||
idea: str, fork_sim_code: str, sim_code: str, temp_storage_path: str, investment: float = 30.0, n_round: int = 500
|
||||
):
|
||||
town = StanfordTown()
|
||||
logger.info("StanfordTown init environment")
|
||||
|
||||
|
|
@ -45,8 +48,8 @@ async def startup(idea: str, fork_sim_code: str, sim_code: str, investment: floa
|
|||
roles.append(role)
|
||||
|
||||
# init temp_storage
|
||||
write_curr_sim_code({"sim_code": sim_code})
|
||||
write_curr_step({"step": reverie_meta.get("step", 0)})
|
||||
write_curr_sim_code({"sim_code": sim_code}, temp_storage_path)
|
||||
write_curr_step({"step": reverie_meta.get("step", 0)}, temp_storage_path)
|
||||
|
||||
await town.hire(roles)
|
||||
|
||||
|
|
@ -56,18 +59,33 @@ async def startup(idea: str, fork_sim_code: str, sim_code: str, investment: floa
|
|||
await town.run(n_round)
|
||||
|
||||
|
||||
def main(idea: str, fork_sim_code: str, sim_code: str, investment: float = 30.0, n_round: int = 500):
|
||||
def main(
|
||||
idea: str,
|
||||
fork_sim_code: str,
|
||||
sim_code: str,
|
||||
temp_storage_path: Optional[str] = None,
|
||||
investment: float = 30.0,
|
||||
n_round: int = 500,
|
||||
):
|
||||
"""
|
||||
Args:
|
||||
idea: idea works as an `inner voice` to the first agent.
|
||||
fork_sim_code: old simulation name to start with
|
||||
sim_code: new simulation name to save simulation result
|
||||
temp_storage_path: generative_agents storage path inside `environment/frontend_server` to
|
||||
investment: the investment of running agents
|
||||
n_round: rounds to run agents
|
||||
"""
|
||||
|
||||
asyncio.run(
|
||||
startup(idea=idea, fork_sim_code=fork_sim_code, sim_code=sim_code, investment=investment, n_round=n_round)
|
||||
startup(
|
||||
idea=idea,
|
||||
fork_sim_code=fork_sim_code,
|
||||
sim_code=sim_code,
|
||||
temp_storage_path=temp_storage_path,
|
||||
investment=investment,
|
||||
n_round=n_round,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,14 +6,13 @@ from typing import Any
|
|||
|
||||
from pydantic import Field
|
||||
|
||||
from examples.st_game.roles.st_role import STRole
|
||||
from examples.st_game.utils.const import MAZE_ASSET_PATH
|
||||
from metagpt.context import Context
|
||||
from metagpt.environment.stanford_town_env.stanford_town_env import StanfordTownEnv
|
||||
from metagpt.logs import logger
|
||||
from metagpt.team import Team
|
||||
|
||||
from examples.st_game.roles.st_role import STRole
|
||||
from examples.st_game.utils.const import MAZE_ASSET_PATH
|
||||
|
||||
|
||||
class StanfordTown(Team):
|
||||
env: StanfordTownEnv = Field(default=None)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,9 @@ async def test_gen_action_details():
|
|||
act_desp = "sleeping"
|
||||
act_dura = "120"
|
||||
|
||||
access_tile = await role.rc.env.observe(EnvAPIAbstract(api_name="access_tile", kwargs={"tile": role.scratch.curr_tile}))
|
||||
access_tile = await role.rc.env.observe(
|
||||
EnvAPIAbstract(api_name="access_tile", kwargs={"tile": role.scratch.curr_tile})
|
||||
)
|
||||
act_world = access_tile["world"]
|
||||
assert act_world == "the Ville"
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@
|
|||
# @Desc : unittest of roles conversation
|
||||
|
||||
from typing import Tuple
|
||||
|
||||
import pytest
|
||||
|
||||
from examples.st_game.plan.converse import agent_conversation
|
||||
from examples.st_game.roles.st_role import STRole
|
||||
from examples.st_game.utils.const import STORAGE_PATH, MAZE_ASSET_PATH
|
||||
from examples.st_game.utils.const import MAZE_ASSET_PATH, STORAGE_PATH
|
||||
from examples.st_game.utils.mg_ga_transform import get_reverie_meta
|
||||
from examples.st_game.utils.utils import copy_folder
|
||||
from metagpt.environment.stanford_town_env.stanford_town_env import StanfordTownEnv
|
||||
|
|
|
|||
|
|
@ -13,8 +13,9 @@ from metagpt.environment.stanford_town_env.stanford_town_env import StanfordTown
|
|||
@pytest.mark.asyncio
|
||||
async def test_observe():
|
||||
role = STRole(
|
||||
sim_code="base_the_ville_isabella_maria_klaus", start_time="February 13, 2023",
|
||||
curr_time="February 13, 2023, 00:00:00"
|
||||
sim_code="base_the_ville_isabella_maria_klaus",
|
||||
start_time="February 13, 2023",
|
||||
curr_time="February 13, 2023, 00:00:00",
|
||||
)
|
||||
role.set_env(StanfordTownEnv(maze_asset_path=MAZE_ASSET_PATH))
|
||||
await role.init_curr_tile()
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ from examples.st_game.actions.run_reflect_action import (
|
|||
AgentFocusPt,
|
||||
AgentInsightAndGuidance,
|
||||
)
|
||||
from examples.st_game.utils.const import MAZE_ASSET_PATH
|
||||
from examples.st_game.roles.st_role import STRole
|
||||
from examples.st_game.utils.const import MAZE_ASSET_PATH
|
||||
from metagpt.environment.stanford_town_env.stanford_town_env import StanfordTownEnv
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# @Desc : data transform of mg <-> ga under storage
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from examples.st_game.utils.const import STORAGE_PATH, TEMP_STORAGE_PATH
|
||||
from metagpt.logs import logger
|
||||
|
|
@ -53,9 +55,11 @@ def get_role_environment(sim_code: str, role_name: str, step: int = 0) -> dict:
|
|||
return role_env
|
||||
|
||||
|
||||
def write_curr_sim_code(curr_sim_code: dict):
|
||||
write_json_file(TEMP_STORAGE_PATH.joinpath("curr_sim_code.json"), curr_sim_code)
|
||||
def write_curr_sim_code(curr_sim_code: dict, temp_storage_path: Optional[Path] = None):
|
||||
temp_storage_path = Path(temp_storage_path) or TEMP_STORAGE_PATH
|
||||
write_json_file(temp_storage_path.joinpath("curr_sim_code.json"), curr_sim_code)
|
||||
|
||||
|
||||
def write_curr_step(curr_step: dict):
|
||||
write_json_file(TEMP_STORAGE_PATH.joinpath("curr_step.json"), curr_step)
|
||||
def write_curr_step(curr_step: dict, temp_storage_path: Optional[Path] = None):
|
||||
temp_storage_path = Path(temp_storage_path) or TEMP_STORAGE_PATH
|
||||
write_json_file(temp_storage_path.joinpath("curr_step.json"), curr_step)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue