Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ repos:
| \.html$
)
args: [
"--init-hook=import sys; sys.path.insert(0, 'alias/src')",
--disable=W0511,
--disable=W0718,
--disable=W0122,
Expand Down
6 changes: 6 additions & 0 deletions alias/src/alias/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@

__version__ = "0.0.1"

__all__ = ["agent", "runtime", "__version__"]

# Import submodules to make them accessible via alias.agent, alias.runtime
# Import at the end to avoid circular import issues
from . import agent # noqa: E402, F401
from . import runtime # noqa: E402, F401
10 changes: 10 additions & 0 deletions alias/src/alias/agent/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
"""Agent module for Alias"""

__all__ = ["agents", "tools", "mock", "utils"]

# Import submodules to make them accessible via alias.agent.agents, etc.
from . import agents # noqa: E402, F401
from . import tools # noqa: E402, F401
from . import mock # noqa: E402, F401
from . import utils # noqa: E402, F401
21 changes: 11 additions & 10 deletions alias/src/alias/agent/agents/_alias_agent_base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
from typing import Optional, Any, Type, Callable
import asyncio
import json
import time
from pydantic import BaseModel
from loguru import logger
import traceback
import json
from typing import Any, Optional, Type

from loguru import logger
from pydantic import BaseModel

from agentscope.agent import ReActAgent
from agentscope.model import ChatModelBase
Expand Down Expand Up @@ -49,6 +50,7 @@ def __init__(

async def _reasoning(self):
"""Override _reasoning to add retry logic."""

# Call the parent class's _reasoning method directly to
# avoid double hook execution
# We need to call the underlying implementation without hooks
Expand All @@ -57,28 +59,28 @@ async def call_parent_reasoning():
# metaclass processing
# Access the method from the class that defines it
# (before metaclass wrapping)
original_method = ReActAgent.__dict__['_reasoning']
original_method = ReActAgent.__dict__["_reasoning"]
# Check if this is the wrapped version by looking for
# the wrapper attributes
if hasattr(original_method, '__wrapped__'):
if hasattr(original_method, "__wrapped__"):
# This is the wrapped version, get the original
original_method = original_method.__wrapped__
return await original_method(self)

for i in range(MODEL_MAX_RETRIES - 1):
try:
return await call_parent_reasoning()
except Exception as e:
except Exception:
logger.warning(
f"Reasoning fail at attempt {i + 1}. "
f"Max attempts {MODEL_MAX_RETRIES}\n"
f"{traceback.format_exc()}"
f"{traceback.format_exc()}",
)
memory_msgs = await self.memory.get_memory()
mem_len = len(memory_msgs)
# ensure the last message has no tool_use before next attempt
if mem_len > 0 and memory_msgs[-1].has_content_blocks(
"tool_use"
"tool_use",
):
await self.memory.delete(index=mem_len - 1)
time.sleep(2)
Expand Down Expand Up @@ -241,7 +243,6 @@ async def _acting(self, tool_call: ToolUseBlock) -> Msg | None:
# Skip non-serializable values
pass


# Skip the printing of the finish function call
if (
tool_call["name"] != self.finish_function_name
Expand Down
Loading
Loading