forked from OpenBMB/AgentVerse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update brainstorming case. fix some bugs.
- Loading branch information
1 parent
5efef41
commit bcadb7d
Showing
15 changed files
with
263 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from __future__ import annotations | ||
import asyncio | ||
from colorama import Fore | ||
|
||
from typing import TYPE_CHECKING, List | ||
|
||
from . import decision_maker_registry | ||
from .base import BaseDecisionMaker | ||
from agentverse.logging import logger | ||
|
||
from agentverse.message import Message | ||
|
||
if TYPE_CHECKING: | ||
from agentverse.agents.base import BaseAgent | ||
from agentverse.message import CriticMessage | ||
|
||
|
||
@decision_maker_registry.register("brainstorming") | ||
class BrainstormingDecisionMaker(BaseDecisionMaker): | ||
""" | ||
Much like the horizontal decision maker, but with some twists: | ||
(1) Solver acts as a summarizer, summarizing the discussion of this turn | ||
(2) After summarizing, all the agents' memory are cleared, and replaced with | ||
the summary (to avoid exceeding maximum context length of the model too fast) | ||
""" | ||
|
||
name: str = "brainstorming" | ||
|
||
async def astep( | ||
self, | ||
agents: List[BaseAgent], | ||
task_description: str, | ||
previous_plan: str = "No solution yet.", | ||
advice: str = "No advice yet.", | ||
*args, | ||
**kwargs, | ||
) -> List[str]: | ||
if advice != "No advice yet.": | ||
self.broadcast_messages( | ||
agents, [Message(content=advice, sender="Evaluator")] | ||
) | ||
for agent in agents[1:]: | ||
review: CriticMessage = await agent.astep( | ||
previous_plan, advice, task_description | ||
) | ||
if review.content != "": | ||
self.broadcast_messages(agents, [review]) | ||
|
||
logger.info("", "Reviews:", Fore.YELLOW) | ||
logger.info( | ||
"", | ||
f"[{review.sender}]: {review.content}", | ||
Fore.YELLOW, | ||
) | ||
|
||
result = agents[0].step(previous_plan, advice, task_description) | ||
for agent in agents: | ||
agent.memory.reset() | ||
self.broadcast_messages( | ||
agents, | ||
[ | ||
Message( | ||
content=result.content, sender="Summary From Previous Discussion" | ||
) | ||
], | ||
) | ||
return [result] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from __future__ import annotations | ||
import asyncio | ||
from colorama import Fore | ||
|
||
from typing import TYPE_CHECKING, List | ||
|
||
from . import decision_maker_registry | ||
from .base import BaseDecisionMaker | ||
from agentverse.logging import typewriter_log, logger | ||
from agentverse.message import Message | ||
|
||
if TYPE_CHECKING: | ||
from agentverse.agents import BaseAgent, SolverAgent, CriticAgent | ||
from agentverse.message import SolverMessage | ||
|
||
|
||
@decision_maker_registry.register("central") | ||
class CentralDecisionMaker(BaseDecisionMaker): | ||
""" | ||
Discuss in a central manner. | ||
""" | ||
|
||
name: str = "central" | ||
|
||
async def astep( | ||
self, | ||
agents: List[BaseAgent], | ||
task_description: str, | ||
previous_plan: str = "No solution yet.", | ||
advice: str = "No advice yet.", | ||
*args, | ||
**kwargs, | ||
) -> List[SolverMessage]: | ||
if advice != "No advice yet.": | ||
agents[1].add_message_to_memory( | ||
[Message(content=advice, sender="Evaluator")] | ||
) | ||
result = await agents[1].astep( | ||
previous_plan, | ||
advice, | ||
task_description, | ||
roles=", ".join( | ||
[ | ||
agent.role_description[0].lower() + agent.role_description[1:] | ||
for agent in agents | ||
] | ||
), | ||
) | ||
agents[1].add_message_to_memory([result]) | ||
result = agents[0].step( | ||
previous_plan, advice, task_description, chat_record=result.content | ||
) | ||
return [result] | ||
|
||
def reset(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
import subprocess | ||
import multiprocessing | ||
from typing import TYPE_CHECKING, Any, List, Tuple | ||
|
||
from agentverse.agents import ExecutorAgent | ||
from agentverse.logging import logger | ||
|
||
from . import BaseExecutor, executor_registry | ||
|
||
|
||
def execute_command(command: str, result_list) -> str: | ||
# TODO: make it more secure | ||
result = subprocess.run(command, capture_output=True, shell=True, encoding="utf-8") | ||
result_list.append(f"STDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}") | ||
# return f"STDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}" | ||
|
||
|
||
@executor_registry.register("coverage-test") | ||
class CoverageTestExecutor(BaseExecutor): | ||
def step( | ||
self, | ||
agent: ExecutorAgent, | ||
task_description: str, | ||
solution: List[str], | ||
*args, | ||
**kwargs, | ||
) -> Any: | ||
from evaluate_commongen import scoring | ||
|
||
coverage, missing_tokens = scoring([solution], [task_description]) | ||
if len(missing_tokens[0]) == 0: | ||
missing_tokens = "No missing tokens." | ||
else: | ||
missing_tokens = ", ".join(missing_tokens[0]) | ||
result = f"Coverage: {coverage*100:.2f}%\nMissing Tokens: {missing_tokens}" | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.