🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
formatting
yzlinf040c73ae990
diff --git a/examples/agent_creator.py b/examples/agent_creator.pyindex 748dc02b1..e03a88c6b 100644--- a/examples/agent_creator.py+++ b/examples/agent_creator.py@@ -43,7 +43,7 @@ class CreateAgent(Action):code_text = CreateAgent.parse_code(rsp)return code_text-+@staticmethoddef parse_code(rsp):pattern = r'```python(.*)```'@@ -85,7 +85,8 @@ if __name__ == "__main__":creator = AgentCreator(agent_template=agent_template)- # msg = """Write an agent called SimpleTester that will take any code snippet (str) and return a testing code (str) for testing+ # msg = """Write an agent called SimpleTester that will take any code snippet (str)+ # and return a testing code (str) for testing# the given code snippet. Use pytest as the testing framework."""msg = """@@ -94,6 +95,6 @@ if __name__ == "__main__":2. run the testing code.You can use pytest as the testing framework."""- result = await creator.run(msg)+ await creator.run(msg)asyncio.run(main())diff --git a/examples/build_customized_agent.py b/examples/build_customized_agent.pyindex 746c8c9fa..dc15ff061 100644--- a/examples/build_customized_agent.py+++ b/examples/build_customized_agent.py@@ -32,7 +32,7 @@ class SimpleWriteCode(Action):def __init__(self, name="SimpleWriteCode", context=None, llm=None):super().__init__(name, context, llm)-+async def run(self, instruction: str):prompt = self.PROMPT_TEMPLATE.format(instruction=instruction)@@ -43,7 +43,7 @@ class SimpleWriteCode(Action):code_text = SimpleWriteCode.parse_code(rsp)return code_text-+@staticmethoddef parse_code(rsp):pattern = r'```python(.*)```'@@ -54,7 +54,7 @@ class SimpleWriteCode(Action):class SimpleRunCode(Action):def __init__(self, name="SimpleRunCode", context=None, llm=None):super().__init__(name, context, llm)-+async def run(self, code_text: str):result = subprocess.run(["python3", "-c", code_text], capture_output=True, text=True)code_result = result.stdout@@ -112,7 +112,7 @@ class RunnableCoder(Role):instruction = msg.contentcode_text = await SimpleWriteCode().run(instruction)msg = Message(content=code_text, role=self.profile, cause_by=todo)-+elif isinstance(todo, SimpleRunCode):code_text = msg.contentrsp = await SimpleRunCode().run(code_text)@@ -137,4 +137,4 @@ async def main(msg="write a function that calculates the sum of a list"):logger.info(result)if __name__ == '__main__':- fire.Fire(main)\ No newline at end of file+ fire.Fire(main)diff --git a/examples/debate.py b/examples/debate.pyindex 3a9abf9bc..05db28070 100644--- a/examples/debate.py+++ b/examples/debate.py@@ -29,7 +29,7 @@ class ShoutOut(Action):def __init__(self, name="ShoutOut", context=None, llm=None):super().__init__(name, context, llm)-+async def run(self, context: str, name: str, opponent_name: str):prompt = self.PROMPT_TEMPLATE.format(context=context, name=name, opponent_name=opponent_name)@@ -51,17 +51,16 @@ class Trump(Role):self._watch([ShoutOut])self.name = "Trump"self.opponent_name = "Biden"-+async def _observe(self) -> int:await super()._observe()- self._rc.news = [- msg for msg in self._rc.news if msg.send_to == self.name- ] # accept messages sent (from opponent) to self, disregard own messages from the last round+ # accept messages sent (from opponent) to self, disregard own messages from the last round+ self._rc.news = [msg for msg in self._rc.news if msg.send_to == self.name]return len(self._rc.news)async def _act(self) -> Message:logger.info(f"{self._setting}: ready to {self._rc.todo}")-+msg_history = self._rc.memory.get_by_actions([ShoutOut])context = []for m in msg_history:@@ -92,17 +91,17 @@ class Biden(Role):self._watch([BossRequirement, ShoutOut])self.name = "Biden"self.opponent_name = "Trump"-+async def _observe(self) -> int:await super()._observe()- self._rc.news = [- msg for msg in self._rc.news if msg.cause_by == BossRequirement or msg.send_to == self.name- ] # accept the very first human instruction (the debate topic) or messages sent (from opponent) to self, disregard own messages from the last round+ # accept the very first human instruction (the debate topic) or messages sent (from opponent) to self,+ # disregard own messages from the last round+ self._rc.news = [msg for msg in self._rc.news if msg.cause_by == BossRequirement or msg.send_to == self.name]return len(self._rc.news)async def _act(self) -> Message:logger.info(f"{self._setting}: ready to {self._rc.todo}")-+msg_history = self._rc.memory.get_by_actions([BossRequirement, ShoutOut])context = []for m in msg_history:@@ -134,7 +133,8 @@ async def startup(idea: str, investment: float = 3.0, n_round: int = 5,def main(idea: str, investment: float = 3.0, n_round: int = 10):"""- :param idea: Debate topic, such as "Topic: The U.S. should commit more in climate change fighting" or "Trump: Climate change is a hoax"+ :param idea: Debate topic, such as "Topic: The U.S. should commit more in climate change fighting"+ or "Trump: Climate change is a hoax":param investment: contribute a certain dollar amount to watch the debate:param n_round: maximum rounds of the debate:return: