Skip to content
Closed
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
3 changes: 3 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install pre-commit black==23.1.0 isort==5.12.0 autoflake==2.0.1
- name: Prepare config file
run: |
cp config/config.example.toml config/config.toml
- name: Run pre-commit hooks
run: pre-commit run --all-files
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,6 @@ data/

# Workspace
workspace/

# Configuration files
config/config.toml
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
- id: black

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand Down
31 changes: 29 additions & 2 deletions app/agent/manus.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, ClassVar, Dict

from pydantic import Field

Expand All @@ -8,6 +8,7 @@
from app.tool.browser_use_tool import BrowserUseTool
from app.tool.file_saver import FileSaver
from app.tool.python_execute import PythonExecute
from app.tool.stock_data_tool import StockSearch
from app.tool.web_search import WebSearch


Expand All @@ -31,13 +32,39 @@ class Manus(ToolCallAgent):
max_observe: int = 2000
max_steps: int = 20

# 特定工具的max_observe配置
tool_specific_max_observe: ClassVar[Dict[str, int]] = {"StockSearch": 13000}

# Add general-purpose tools to the tool collection
available_tools: ToolCollection = Field(
default_factory=lambda: ToolCollection(
PythonExecute(), WebSearch(), BrowserUseTool(), FileSaver(), Terminate()
PythonExecute(),
WebSearch(),
BrowserUseTool(),
FileSaver(),
Terminate(),
StockSearch(),
)
)

async def _set_max_observe_for_tool(self, tool_name: str):
"""根据使用的工具类型设置不同的max_observe值"""
if tool_name in self.tool_specific_max_observe:
self.max_observe = self.tool_specific_max_observe[tool_name]
else:
self.max_observe = 2000 # 默认值

async def use_tool(self, *args, **kwargs):
"""重写use_tool方法,在调用工具前设置合适的max_observe值"""
tool_name = kwargs.get("name") or (args[0] if args else None)
old_max_observe = self.max_observe
if tool_name:
await self._set_max_observe_for_tool(tool_name)
print(
f"工具调用: {tool_name}, max_observe值: {self.max_observe} (原值: {old_max_observe})"
)
return await super().use_tool(*args, **kwargs)

async def _handle_special_tool(self, name: str, result: Any, **kwargs):
if not self._is_special_tool(name):
return
Expand Down
2 changes: 2 additions & 0 deletions app/prompt/manus.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

WebSearch: Perform web information retrieval

StockSearch: Used to obtain real-time stock data, time-based data, and historical data.

Terminate: End the current interaction when the task is complete or when you need additional information from the user. Use this tool to signal that you've finished addressing the user's request or need clarification before proceeding further.

Based on user needs, proactively select the most appropriate tool or combination of tools. For complex tasks, you can break down the problem and use different tools step by step to solve it. After using each tool, clearly explain the execution results and suggest the next steps.
Expand Down
2 changes: 2 additions & 0 deletions app/tool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from app.tool.bash import Bash
from app.tool.create_chat_completion import CreateChatCompletion
from app.tool.planning import PlanningTool
from app.tool.stock_data_tool import StockSearch
from app.tool.str_replace_editor import StrReplaceEditor
from app.tool.terminate import Terminate
from app.tool.tool_collection import ToolCollection
Expand All @@ -15,4 +16,5 @@
"ToolCollection",
"CreateChatCompletion",
"PlanningTool",
"StockSearch",
]
Loading