mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-17 15:35:21 +02:00
Reflect测试样例
This commit is contained in:
parent
90bb3f94f6
commit
6f449f1505
5 changed files with 35 additions and 24 deletions
|
|
@ -24,11 +24,15 @@ class AgentFocusPt(STAction):
|
|||
return False
|
||||
|
||||
def _func_cleanup(self, llm_resp: str, prompt: str = "") -> list:
|
||||
llm_resp = "1) " + llm_resp.strip()
|
||||
ret = []
|
||||
for i in llm_resp.split("\n"):
|
||||
ret += [i.split(") ")[-1]]
|
||||
return ret
|
||||
try:
|
||||
return llm_resp
|
||||
# llm_resp = "1) " + llm_resp.strip()
|
||||
# ret = []
|
||||
# for i in llm_resp.split("\n"):
|
||||
# ret += [i.split(") ")[-1]]
|
||||
# return ret
|
||||
except Exception as exp:
|
||||
print(f"cleanup 错误 {exp}")
|
||||
|
||||
def _func_fail_default_resp(self) -> str:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -174,13 +174,13 @@ class AgentMemory(Memory):
|
|||
poignancy = node_details["poignancy"]
|
||||
keywords = set(node_details["keywords"])
|
||||
filling = node_details["filling"]
|
||||
if node_details["type"] == "thought":
|
||||
if node_type == "thought":
|
||||
self.add_thought(created, expiration, s, p, o,
|
||||
description, keywords, poignancy, embedding_pair, filling)
|
||||
if node_details["type"] == "event":
|
||||
if node_type == "event":
|
||||
self.add_event(created, expiration, s, p, o,
|
||||
description, keywords, poignancy, embedding_pair, filling)
|
||||
if node_details["type"] == "chat":
|
||||
if node_type == "chat":
|
||||
self.add_chat(created, expiration, s, p, o,
|
||||
description, keywords, poignancy, embedding_pair, filling)
|
||||
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ def run_reflect(role: "STRole"):
|
|||
created, expiration, s, p, o, thought, keywords,
|
||||
thought_poignancy, thought_embedding_pair, evidence
|
||||
)
|
||||
logger.info(f"主谓宾为:{s}{p}{o},描述为{thought}")
|
||||
|
||||
|
||||
def reflection_trigger(role: "STRole"):
|
||||
|
|
@ -138,14 +139,10 @@ def reflection_trigger(role: "STRole"):
|
|||
True if we are running a new reflection.
|
||||
False otherwise.
|
||||
"""
|
||||
logger.info(
|
||||
role.scratch.name, "role.scratch.importance_trigger_curr::",
|
||||
role.scratch.importance_trigger_curr
|
||||
)
|
||||
logger.info(role.scratch.importance_trigger_max)
|
||||
logger.info(f"{role.scratch.name} role.scratch.importance_trigger_curr:: {role.scratch.importance_trigger_curr}"),
|
||||
|
||||
if (role.scratch.importance_trigger_curr <= 0 and
|
||||
[] != role.memory.seq_event + role.memory.seq_thought):
|
||||
[] != role.memory.event_list + role.memory.thought_list):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -309,9 +309,9 @@ class STRole(Role):
|
|||
# TODO re-add result into memory
|
||||
pass
|
||||
|
||||
async def reflect(self):
|
||||
def reflect(self):
|
||||
# TODO reflection if meet reflect condition
|
||||
role_reflect(self)
|
||||
result = role_reflect(self)
|
||||
# TODO re-add result to memory
|
||||
# 已封装到Reflect函数之中
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,29 @@
|
|||
|
||||
import pytest
|
||||
from examples.st_game.roles.st_role import STRole
|
||||
from examples.st_game.actions.run_reflect_action import AgentFocusPt
|
||||
from metagpt.logs import logger
|
||||
|
||||
|
||||
class TestReflect:
|
||||
class TestReflectFunction:
|
||||
@pytest.fixture
|
||||
def init_agent(self):
|
||||
# 创建一个AgentMemory实例并返回,可以在所有测试用例中共享
|
||||
role = STRole('Isabella Rodriguez', 'STMember', 'base_the_vile_isabella_maria_klaus')
|
||||
# 创建一个STRole实例,注意从GA中copy过来JSON文件
|
||||
role = STRole(sim_code="July1_the_ville_isabella_maria_klaus-step-3-11", start_date='February 13, 2023', curr_time='February 13, 2023, 14:53:10')
|
||||
logger.info(role.scratch.name)
|
||||
logger.info(f"记忆长度为{len(role.memory.storage)}")
|
||||
return role
|
||||
|
||||
def test_focus(self, init_agent):
|
||||
def test_fuction_point_action(self,init_agent):
|
||||
"""
|
||||
|
||||
"""
|
||||
run_focus = AgentFocusPt()
|
||||
statements = "" # 这个statements 与 n 设置是遵循reflect里面实际设置# 来的,你写的时候可以对应代码看一下
|
||||
run_focus.run(init_agent, statements, n=3)
|
||||
|
||||
# 测试全部Reflection功能
|
||||
def test_reflect_function(self, init_agent):
|
||||
# 修改 近期 importace 确保Reflect机制能够触发
|
||||
init_agent.scratch.importance_trigger_curr = -1
|
||||
init_agent.reflect()
|
||||
"""
|
||||
测试思路
|
||||
1.
|
||||
"""
|
||||
Loading…
Add table
Add a link
Reference in a new issue