-
Notifications
You must be signed in to change notification settings - Fork 512
Fix/general run #917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
suluyana
wants to merge
67
commits into
modelscope:main
Choose a base branch
from
suluyana:fix/general_run
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix/general run #917
Changes from all commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
6baa994
fix: video gen exclude edit_file
9c8205c
Merge branch 'main' of https://github.com/modelscope/ms-agent
94b833f
Merge branch 'main' of https://github.com/modelscope/ms-agent
11bcf06
enhance deep research v2
dd3f185
Merge branch 'main' of https://github.com/modelscope/ms-agent
693d9e9
feat: support search local paths through sirchmunk
05cb676
refactor: optimize architecture, restrict researcher report edits, up…
2977ba0
Update ms_agent/agent/llm_agent.py
suluyana 879dba4
Apply suggestion from @gemini-code-assist[bot]
suluyana 1dd49b6
fix local code executor; refine workflow and prompt (03)
c27347f
fix timeout; support for running subagent in process; support for pos…
5920dc4
refine readme for deep research; add run_benchmark.sh; fix counting c…
14cb873
Merge branch 'main' of https://github.com/modelscope/ms-agent into fe…
5202823
full modify?
24eb500
fix lint
986b34f
enrich researcher's reflection strategy to enhance stability
e6ad3e9
Merge branch 'main' of https://github.com/modelscope/ms-agent
88aaae6
Merge remote-tracking branch 'origin' into feat/tools
fec8bfe
mv localsearch to tools
b437bdc
thinking support beta; search_file_content fix
86a3ba8
support API key pool construction; support for reasoning model
8a32ce5
fix lint
393f23c
support for vertex type anthropic llm; refine reasoning output
49919ab
Merge branch 'main' of https://github.com/modelscope/ms-agent
e00c296
feat: add snapshot/rollback system to agent runtime
f08a15e
support for response api; optimize log output formatting
6bfb262
feat: merge SplitTask into AgentTool, add TaskManager infrastructure
db45457
feat: add run_in_background support to AgentTool
47bf056
feat: add TaskControlTool for LLM-accessible task management
e3b62dc
fix: hold strong reference to background watcher asyncio.Task to prev…
6286732
fix: cancel watcher tasks on AgentTool cleanup; export TaskControlToo…
c326139
fix: correct malformed XML in TaskManager._format_notification
b103ffa
test: add smoke tests for TaskManager, AgentTool dynamic spec, TaskCo…
7a96f8e
feat: stream sub-agent execution trace to file in real time
5825111
Merge branch 'main' of https://github.com/modelscope/ms-agent into fe…
6a1ba9f
fix lint
c6b1e3b
Merge branch 'main' of https://github.com/modelscope/ms-agent
2f2dbb0
Merge branch 'main' of https://github.com/modelscope/ms-agent
193e4a1
Merge remote-tracking branch 'origin' into feat/git
b3feb1a
feat: workspace policy, shell artifacts, TaskManager, grep/glob tools
ebbc72a
chore(projects): align configs with filesystem and workspace search t…
94ba0c3
refactor(tools): merge grep/glob into FileSystemTool
9841444
Merge branch 'feat/dr_reasoning' of https://github.com/alcholiclg/ms-…
ec5fb1a
feat(search): add Tavily engine, extract fetcher, and dr_bench wiring
cb75af3
fix(jina): align reader with websearch (meta fetch + playwright fallb…
87ae4ef
Merge origin/feat/git into bench/tavily-0413 (snapshot utils; keep be…
18a5683
chore(tools): use origin/feat/git filesystem_tool on bench/tavily-0413
e59618d
Merge feat/git into bench/tavily-0413; resolve prompts/reporter_callb…
ecf350b
fix(dr v2): align tavily yaml file_system include with grep/glob/edit…
7b49a52
Merge feat/agent-tool-overhaul into bench/tavily-0413
a5d4267
fix(filesystem): drop read-cache staleness gate for writes
00c8e86
fix(deep-research): harden tools, snapshots, and reporter/searcher co…
e5890f6
Merge branch 'bench/tavily-0413' into feat/tools
67668e9
fix lint
2d96611
Revert "fix lint"
34d5e92
fix lint
4d8129b
feat: harden tool system, agent rollback, and Python 3.9 compatibility
84aa0a6
feat: enable file_system and code_executor tools in default agent config
0d6053b
merge: integrate upstream/main into feat/self_improve
90dea45
fix: resolve 10 permission framework false positives (TB 2.1: 60.7% →…
6fc5354
fix: use Optional[str] for runtime type alias in path_extractors.py
952aff2
feat: add tb21-bench.sh benchmark management script
e613248
fix: restore accidentally deleted harbor_terminal_bench_agent.py
594b2c2
Delete ms_agent/benchmark/harbor_terminal_bench_agent.py
suluyana 9a76a7b
fix: harden tool edge cases from code review feedback
461c46f
chore: untrack self_improve files from permission fix commit
d29b5f6
chore: untrack tb21-bench.sh from permission fix branch
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ MANIFEST | |
| *.spec | ||
| release.sh | ||
| build.sh | ||
| scripts/tb21-bench.sh | ||
| *.html | ||
|
|
||
| # Installer logs | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from __future__ import annotations | ||
| import os | ||
| from typing import Any, Dict, List | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from __future__ import annotations | ||
| import os | ||
| from typing import Any, Dict, List, Optional | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from __future__ import annotations | ||
| from ms_agent.utils.logger import get_logger | ||
|
|
||
| logger = get_logger() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from __future__ import annotations | ||
| import logging | ||
| import sys | ||
| from typing import Any | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from __future__ import annotations | ||
| from acp import RequestError | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from __future__ import annotations | ||
| import asyncio | ||
| import os | ||
| import secrets | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from __future__ import annotations | ||
| import logging | ||
| import os | ||
| import sys | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from __future__ import annotations | ||
| import os | ||
| import sys | ||
| from typing import Any, Dict | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from __future__ import annotations | ||
| import logging | ||
| import sys | ||
| from typing import Any | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from __future__ import annotations | ||
| import asyncio | ||
| import os | ||
| import uuid | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| """Callback that detects stuck loops and injects strategy-variation prompts. | ||
|
|
||
| When the agent repeats the same tool call (same name + same arguments) multiple | ||
| times without making progress, this callback injects a user message encouraging | ||
| a different approach. After ``max_warnings`` injections, the callback forces | ||
| the agent to stop to avoid wasting remaining API budget. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import hashlib | ||
| import json | ||
| from collections import Counter | ||
| from dataclasses import dataclass | ||
| from typing import List | ||
|
|
||
| from omegaconf import DictConfig | ||
|
|
||
| from ms_agent.agent.runtime import Runtime | ||
| from ms_agent.callbacks.base import Callback | ||
| from ms_agent.llm.utils import Message | ||
| from ms_agent.utils.logger import get_logger | ||
|
|
||
| logger = get_logger() | ||
|
|
||
| _DEFAULT_THRESHOLD = 3 | ||
| _DEFAULT_LOOKBACK = 8 | ||
| _DEFAULT_MAX_WARNINGS = 2 | ||
|
|
||
| _STRATEGY_PROMPT = ( | ||
| "IMPORTANT: You have been repeating the same approach multiple times " | ||
| "without making progress. The exact same tool call or command has been " | ||
| "attempted {count} times with the same arguments.\n\n" | ||
| "Repeated action: {description}\n\n" | ||
| "Please try a fundamentally different strategy. Consider:\n" | ||
| "1. Check whether the prerequisites for your approach are actually met.\n" | ||
| "2. Break the problem into smaller, verifiable sub-steps.\n" | ||
| "3. Use a different tool or a different command to achieve the same goal.\n" | ||
| "4. Read error messages carefully — they often suggest specific fixes.\n" | ||
| "5. If a dependency is missing, install it before retrying.\n\n" | ||
| "Do NOT repeat the same command again." | ||
| ) | ||
|
|
||
| _FORCE_STOP_PROMPT = ( | ||
| "You have been warned multiple times about repeating the same approach, " | ||
| "but continue to retry the same failing action. " | ||
| "To conserve resources, execution is being stopped. " | ||
| "Please review the errors above and formulate a new plan before " | ||
| "the next attempt." | ||
| ) | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class _Repetition: | ||
| key: str | ||
| tool_name: str | ||
| count: int | ||
| description: str | ||
|
|
||
|
|
||
| def _args_hash(arguments: str) -> str: | ||
| try: | ||
| parsed = json.loads(arguments) if isinstance(arguments, str) else arguments | ||
| except (json.JSONDecodeError, TypeError): | ||
| parsed = arguments | ||
| canonical = json.dumps(parsed, sort_keys=True, ensure_ascii=False) | ||
| return hashlib.md5(canonical.encode("utf-8")).hexdigest()[:12] | ||
|
|
||
|
|
||
| class RepetitionGuardCallback(Callback): | ||
| """Detects stuck loops and injects strategy-variation prompts.""" | ||
|
|
||
| def __init__(self, config: DictConfig) -> None: | ||
| super().__init__(config) | ||
| guard_cfg = getattr(config, "repetition_guard", None) or {} | ||
| self.threshold: int = int(guard_cfg.get("threshold", _DEFAULT_THRESHOLD)) | ||
| self.lookback: int = int(guard_cfg.get("lookback_rounds", _DEFAULT_LOOKBACK)) | ||
| self.max_warnings: int = int(guard_cfg.get("max_warnings", _DEFAULT_MAX_WARNINGS)) | ||
| self._warnings_given: int = 0 | ||
| self._warned_keys: set[str] = set() | ||
|
|
||
| async def after_tool_call(self, runtime: Runtime, messages: List[Message]) -> None: | ||
| if self._warnings_given >= self.max_warnings: | ||
| logger.info( | ||
| "[RepetitionGuard] Max warnings (%d) reached — forcing stop.", | ||
| self.max_warnings, | ||
| ) | ||
| messages.append(Message(role="user", content=_FORCE_STOP_PROMPT)) | ||
| runtime.should_stop = True | ||
| return | ||
|
|
||
| recent = _extract_recent_tool_calls(messages, self.lookback) | ||
| repetition = _detect_repetition(recent, self.threshold) | ||
|
|
||
| if repetition is None: | ||
| return | ||
| if repetition.key in self._warned_keys: | ||
| return | ||
|
|
||
| self._warned_keys.add(repetition.key) | ||
| self._warnings_given += 1 | ||
| logger.info( | ||
| "[RepetitionGuard] Stuck loop detected (%s, %dx). Injecting strategy prompt. " | ||
| "Warning %d/%d.", | ||
| repetition.tool_name, | ||
| repetition.count, | ||
| self._warnings_given, | ||
| self.max_warnings, | ||
| ) | ||
| runtime.should_stop = False | ||
| prompt = _STRATEGY_PROMPT.format( | ||
| count=repetition.count, | ||
| description=repetition.description, | ||
| ) | ||
| messages.append(Message(role="user", content=prompt)) | ||
|
|
||
|
|
||
| def _extract_recent_tool_calls( | ||
| messages: List[Message], | ||
| lookback: int, | ||
| ) -> list[tuple[str, str, str]]: | ||
| """Return ``(tool_name, args_hash, description)`` for recent rounds. | ||
|
|
||
| Walks backwards through *messages* collecting assistant tool-call entries. | ||
| Stops after scanning *lookback* assistant-with-tool-calls messages. | ||
| """ | ||
| calls: list[tuple[str, str, str]] = [] | ||
| rounds_seen = 0 | ||
|
|
||
| for msg in reversed(messages): | ||
| if rounds_seen >= lookback: | ||
| break | ||
| if msg.role == "assistant" and msg.tool_calls: | ||
| rounds_seen += 1 | ||
| for tc in msg.tool_calls: | ||
| name = tc.get("tool_name", "") | ||
| raw_args = tc.get("arguments", "{}") | ||
| ah = _args_hash(raw_args) | ||
| desc = _summarize_call(name, raw_args) | ||
| calls.append((name, ah, desc)) | ||
|
|
||
| return calls | ||
|
|
||
|
|
||
| def _detect_repetition( | ||
| calls: list[tuple[str, str, str]], | ||
| threshold: int, | ||
| ) -> _Repetition | None: | ||
| if not calls: | ||
| return None | ||
|
|
||
| key_counts: Counter[str] = Counter() | ||
| key_to_info: dict[str, tuple[str, str]] = {} | ||
|
|
||
| for name, ah, desc in calls: | ||
| key = f"{name}:{ah}" | ||
| key_counts[key] += 1 | ||
| if key not in key_to_info: | ||
| key_to_info[key] = (name, desc) | ||
|
|
||
| most_common_key, count = key_counts.most_common(1)[0] | ||
| if count < threshold: | ||
| return None | ||
|
|
||
| tool_name, description = key_to_info[most_common_key] | ||
| return _Repetition( | ||
| key=most_common_key, | ||
| tool_name=tool_name, | ||
| count=count, | ||
| description=description, | ||
| ) | ||
|
|
||
|
|
||
| def _summarize_call(tool_name: str, raw_args: str) -> str: | ||
| try: | ||
| args = json.loads(raw_args) if isinstance(raw_args, str) else raw_args | ||
| except (json.JSONDecodeError, TypeError): | ||
| args = raw_args | ||
|
|
||
| if isinstance(args, dict) and "command" in args: | ||
| cmd = str(args["command"]) | ||
| if len(cmd) > 120: | ||
| cmd = cmd[:120] + "..." | ||
| return f"{tool_name}(command={cmd})" | ||
|
|
||
| summary = json.dumps(args, ensure_ascii=False) | ||
| if len(summary) > 120: | ||
| summary = summary[:120] + "..." | ||
| return f"{tool_name}({summary})" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| # Copyright (c) ModelScope Contributors. All rights reserved. | ||
| from ms_agent.callbacks.input_callback import InputCallback | ||
| from ms_agent.callbacks.repetition_guard import RepetitionGuardCallback | ||
|
|
||
| callbacks_mapping = {'input_callback': InputCallback} | ||
| callbacks_mapping = { | ||
| 'input_callback': InputCallback, | ||
| 'repetition_guard': RepetitionGuardCallback, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 PR 里有比较多的脚本在头部新增了
from __future__ import annotations,主要解决的问题是?如果暂时没有类型注解延迟求值需求的话是不是可以先不加这些。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
主要解决兼容py3.9的问题