mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-03 21:02:38 +02:00
Merge branch 'geekan/dev' into feature/rebuild
This commit is contained in:
commit
9e84e63529
4 changed files with 30 additions and 9 deletions
|
|
@ -297,6 +297,6 @@ class Engineer(Role):
|
|||
self.set_todo(self.summarize_todos[0])
|
||||
|
||||
@property
|
||||
def todo(self) -> str:
|
||||
def action_description(self) -> str:
|
||||
"""AgentStore uses this attribute to display to the user what actions the current role should take."""
|
||||
return self.next_todo_action
|
||||
|
|
|
|||
|
|
@ -523,19 +523,34 @@ class Role(SerializationMixin, ContextMixin, BaseModel):
|
|||
return not self.rc.news and not self.rc.todo and self.rc.msg_buffer.empty()
|
||||
|
||||
async def think(self) -> Action:
|
||||
"""The exported `think` function"""
|
||||
"""
|
||||
Export SDK API, used by AgentStore RPC.
|
||||
The exported `think` function
|
||||
"""
|
||||
await self._observe() # For compatibility with the old version of the Agent.
|
||||
await self._think()
|
||||
return self.rc.todo
|
||||
|
||||
async def act(self) -> ActionOutput:
|
||||
"""The exported `act` function"""
|
||||
"""
|
||||
Export SDK API, used by AgentStore RPC.
|
||||
The exported `act` function
|
||||
"""
|
||||
msg = await self._act()
|
||||
return ActionOutput(content=msg.content, instruct_content=msg.instruct_content)
|
||||
|
||||
@property
|
||||
def first_action(self) -> str:
|
||||
"""AgentStore uses this attribute to display to the user what actions the current role should take."""
|
||||
# FIXME: this is a hack, we should not use the first action to represent the todo
|
||||
def action_description(self) -> str:
|
||||
"""
|
||||
Export SDK API, used by AgentStore RPC and Agent.
|
||||
AgentStore uses this attribute to display to the user what actions the current role should take.
|
||||
`Role` provides the default property, and this property should be overridden by children classes if necessary,
|
||||
as demonstrated by the `Engineer` class.
|
||||
"""
|
||||
if self.rc.todo:
|
||||
if self.rc.todo.desc:
|
||||
return self.rc.todo.desc
|
||||
return any_to_name(self.rc.todo)
|
||||
if self.actions:
|
||||
return any_to_name(self.actions[0])
|
||||
return ""
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ from typing import Any, List, Tuple, Union
|
|||
import aiofiles
|
||||
import loguru
|
||||
from pydantic_core import to_jsonable_python
|
||||
from tenacity import RetryCallState, _utils
|
||||
from tenacity import RetryCallState, RetryError, _utils
|
||||
|
||||
from metagpt.const import MESSAGE_ROUTE_TO_ALL
|
||||
from metagpt.logs import logger
|
||||
|
|
@ -505,7 +505,7 @@ def role_raise_decorator(func):
|
|||
self.rc.memory.delete(self.latest_observed_msg)
|
||||
# raise again to make it captured outside
|
||||
raise Exception(format_trackback_info(limit=None))
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
if self.latest_observed_msg:
|
||||
logger.warning(
|
||||
"There is a exception in role's execution, in order to resume, "
|
||||
|
|
@ -514,6 +514,12 @@ def role_raise_decorator(func):
|
|||
# remove role newest observed msg to make it observed again
|
||||
self.rc.memory.delete(self.latest_observed_msg)
|
||||
# raise again to make it captured outside
|
||||
if isinstance(e, RetryError):
|
||||
last_error = e.last_attempt._exception
|
||||
name = any_to_str(last_error)
|
||||
if re.match(r"^openai\.", name) or re.match(r"^httpx\.", name):
|
||||
raise last_error
|
||||
|
||||
raise Exception(format_trackback_info(limit=None))
|
||||
|
||||
return wrapper
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ lancedb==0.4.0
|
|||
langchain==0.0.352
|
||||
loguru==0.6.0
|
||||
meilisearch==0.21.0
|
||||
numpy==1.24.3
|
||||
numpy>=1.24.3
|
||||
openai==1.6.0
|
||||
openpyxl
|
||||
beautifulsoup4==4.12.2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue