From 548c402316b22c788caf9b5ebb63fe5e29a0ca83 Mon Sep 17 00:00:00 2001 From: xiangjinyu <1376193973@qq.com> Date: Wed, 12 Mar 2025 17:23:08 +0800 Subject: [PATCH] add max_observe in toolcall and manus --- app/agent/manus.py | 2 ++ app/agent/toolcall.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/agent/manus.py b/app/agent/manus.py index 7fa4b69..1472a57 100644 --- a/app/agent/manus.py +++ b/app/agent/manus.py @@ -26,6 +26,8 @@ class Manus(ToolCallAgent): system_prompt: str = SYSTEM_PROMPT next_step_prompt: str = NEXT_STEP_PROMPT + max_observe: int = 2000 + # Add general-purpose tools to the tool collection available_tools: ToolCollection = Field( default_factory=lambda: ToolCollection( diff --git a/app/agent/toolcall.py b/app/agent/toolcall.py index b3b6439..19245c1 100644 --- a/app/agent/toolcall.py +++ b/app/agent/toolcall.py @@ -1,5 +1,5 @@ import json -from typing import Any, List, Literal +from typing import Any, List, Literal, Optional, Union from pydantic import Field @@ -31,6 +31,7 @@ class ToolCallAgent(ReActAgent): tool_calls: List[ToolCall] = Field(default_factory=list) max_steps: int = 30 + max_observe: Optional[Union[int, bool]] = None async def think(self) -> bool: """Process current state and decide next actions using tools""" @@ -114,6 +115,9 @@ class ToolCallAgent(ReActAgent): f"🎯 Tool '{command.function.name}' completed its mission! Result: {result}" ) + if self.max_observe: + result = result[: self.max_observe] + # Add tool response to memory tool_msg = Message.tool_message( content=result, tool_call_id=command.id, name=command.function.name