Add pre commit (#26)

This commit is contained in:
Lamont Huffman
2025-11-05 11:44:19 +08:00
committed by GitHub
parent 2164371e64
commit 30d86efbb3
33 changed files with 565 additions and 496 deletions

View File

@@ -1,35 +1,46 @@
# -*- coding: utf-8 -*-
"""Deep Research Agent"""
# pylint: disable=too-many-lines, no-name-in-module
import asyncio
import json
import os
from copy import deepcopy
import json
import asyncio
from typing import Type, Optional, Any, Tuple
from datetime import datetime
from typing import Any, Optional, Tuple, Type
from copy import deepcopy
import shortuuid
from agentscope import logger, setup_logger
from agentscope.agent import ReActAgent
from agentscope.formatter import FormatterBase
from agentscope.mcp import StatefulClientBase
from agentscope.memory import MemoryBase
from agentscope.message import Msg, TextBlock, ToolResultBlock, ToolUseBlock
from agentscope.model import ChatModelBase
from agentscope.tool import ToolResponse, view_text_file, write_text_file
from pydantic import BaseModel
from ..agent_deep_research.utils import (
get_dynamic_tool_call_json,
get_structure_output,
load_prompt_dict,
truncate_search_result,
)
from .built_in_prompt.promptmodule import (
FollowupJudge,
ReflectFailure,
from built_in_prompt.promptmodule import (
SubtasksDecomposition,
WebExtraction,
FollowupJudge,
ReflectFailure,
)
from utils import (
truncate_search_result,
load_prompt_dict,
get_dynamic_tool_call_json,
get_structure_output,
)
from agentscope import logger, setup_logger
from agentscope.mcp import StatefulClientBase
from agentscope.agent import ReActAgent
from agentscope.model import ChatModelBase
from agentscope.formatter import FormatterBase
from agentscope.memory import MemoryBase
from agentscope.tool import (
ToolResponse,
view_text_file,
write_text_file,
)
from agentscope.message import (
Msg,
ToolUseBlock,
TextBlock,
ToolResultBlock,
)
_DEEP_RESEARCH_AGENT_DEFAULT_SYS_PROMPT = "You're a helpful assistant."
@@ -149,7 +160,7 @@ class DeepResearchAgent(ReActAgent):
# register all necessary tools for deep research agent
self.toolkit.register_tool_function(view_text_file)
self.toolkit.register_tool_function(write_text_file)
asyncio.create_task(
asyncio.get_running_loop().create_task(
self.toolkit.register_mcp_client(search_mcp_client),
)
@@ -213,16 +224,12 @@ class DeepResearchAgent(ReActAgent):
reasoning_prompt = self.prompt_dict["reasoning_prompt"].format_map(
{
"objective": self.current_subtask[-1].objective,
"meta_planner_agent": (
cur_plan
if cur_plan
else "There is no working meta_planner_agent now."
),
"knowledge_gap": (
f"## Knowledge Gaps:\n {cur_know_gap}"
if cur_know_gap
else ""
),
"plan": cur_plan
if cur_plan
else "There is no working plan now.",
"knowledge_gap": f"## Knowledge Gaps:\n {cur_know_gap}"
if cur_know_gap
else "",
"depth": len(self.current_subtask),
},
)
@@ -300,7 +307,9 @@ class DeepResearchAgent(ReActAgent):
# Async generator handling
async for chunk in tool_res:
# Turn into a tool result block
tool_res_msg.content[0]["output"] = chunk.content # type: ignore[index]
tool_res_msg.content[0][ # type: ignore[index]
"output"
] = chunk.content
# Skip the printing of the finish function call
if (
@@ -488,13 +497,14 @@ class DeepResearchAgent(ReActAgent):
async def decompose_and_expand_subtask(self) -> ToolResponse:
"""Identify the knowledge gaps of the current subtask and generate a
working meta_planner_agent by subtask decomposition. The working meta_planner_agent includes
working meta_planner_agent by subtask decomposition.
The working meta_planner_agent includes
necessary steps for task completion and expanded steps.
Returns:
ToolResponse:
The knowledge gaps and working meta_planner_agent of the current subtask
in JSON format.
The knowledge gaps and working meta_planner_agent
of the current subtask in JSON format.
"""
if len(self.current_subtask) <= self.max_depth:
decompose_sys_prompt = self.prompt_dict["decompose_sys_prompt"]
@@ -947,7 +957,8 @@ class DeepResearchAgent(ReActAgent):
Returns:
ToolResponse:
The reflection about meta_planner_agent rephrasing and subtask decomposition.
The reflection about meta_planner_agent
rephrasing and subtask decomposition.
"""
reflect_sys_prompt = self.prompt_dict["reflect_sys_prompt"]
conversation_history = ""