Synchronize Instances from AgentScope (#29)

This commit is contained in:
Lamont Huffman
2025-11-07 10:00:43 +08:00
committed by GitHub
parent 30d86efbb3
commit 1558fb86f9
9 changed files with 69 additions and 73 deletions

View File

@@ -20,7 +20,7 @@ class SubtasksDecomposition(BaseModel):
working_plan: str = Field(
description=(
"A logically ordered step-by-step working "
"meta_planner_agent (3-5 steps), each step starting with "
"plan (3-5 steps), each step starting with "
"its number (1., 2., etc), including both "
"core and expansion steps. Expanded steps "
"should be clearly marked with (EXPANSION) "
@@ -85,7 +85,7 @@ class ReflectFailure(BaseModel):
"subtask needs to be rephrased due "
"to a design flaw or misunderstanding. "
"If rephrasing is needed, provide the "
"modified working meta_planner_agent with only the "
"modified working plan with only the "
"inappropriate subtask replaced by its "
"improved version."
),
@@ -95,14 +95,14 @@ class ReflectFailure(BaseModel):
"properties": {
"need_rephrase": {
"type": "boolean",
"description": "Set to 'true' if the failed"
" subtask needs to be rephrased due to a design "
"description": "Set to 'true' if the failed subtask "
"needs to be rephrased due to a design "
"flaw or misunderstanding; otherwise, 'false'.",
},
"rephrased_plan": {
"type": "string",
"description": "The modified working "
"meta_planner_agent with only the inappropriate "
"description": "The modified working plan "
"with only the inappropriate "
"subtask replaced by its improved version. If no "
"rephrasing is needed, provide an empty string.",
},

View File

@@ -8,9 +8,7 @@ import asyncio
from typing import Type, Optional, Any, Tuple
from datetime import datetime
from copy import deepcopy
import shortuuid
from pydantic import BaseModel
from built_in_prompt.promptmodule import (
@@ -25,6 +23,7 @@ from utils import (
get_dynamic_tool_call_json,
get_structure_output,
)
from agentscope import logger, setup_logger
from agentscope.mcp import StatefulClientBase
from agentscope.agent import ReActAgent
@@ -43,6 +42,7 @@ from agentscope.message import (
ToolResultBlock,
)
_DEEP_RESEARCH_AGENT_DEFAULT_SYS_PROMPT = "You're a helpful assistant."
_LOG_DIR = os.path.join(os.path.dirname(__file__), "log")
@@ -196,7 +196,7 @@ class DeepResearchAgent(ReActAgent):
SubTaskItem(objective=self.user_query),
)
# Identify the expected output and generate a meta_planner_agent
# Identify the expected output and generate a plan
await self.decompose_and_expand_subtask()
msg.content += (
f"\nExpected Output:\n{self.current_subtask[0].knowledge_gaps}"
@@ -214,7 +214,7 @@ class DeepResearchAgent(ReActAgent):
)
for _ in range(self.max_iters):
# Generate the working meta_planner_agent first
# Generate the working plan first
if not self.current_subtask[-1].working_plan:
await self.decompose_and_expand_subtask()
@@ -497,23 +497,20 @@ 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 plan by subtask decomposition. The working plan 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 plan of the current subtask
in JSON format.
"""
if len(self.current_subtask) <= self.max_depth:
decompose_sys_prompt = self.prompt_dict["decompose_sys_prompt"]
previous_plan = ""
for i, subtask in enumerate(self.current_subtask):
previous_plan += (
f"The {i}-th meta_planner_agent: {subtask.working_plan}\n"
)
previous_plan += f"The {i}-th plan: {subtask.working_plan}\n"
previous_plan_inst = self.prompt_dict[
"previous_plan_inst"
].format_map(
@@ -716,7 +713,7 @@ class DeepResearchAgent(ReActAgent):
async def summarize_intermediate_results(self) -> ToolResponse:
"""Summarize the intermediate results into a report when a step
in working meta_planner_agent is completed.
in working plan is completed.
Returns:
ToolResponse:
@@ -740,9 +737,7 @@ class DeepResearchAgent(ReActAgent):
"user",
self.prompt_dict["summarize_hint"].format_map(
{
"meta_planner_agent": self.current_subtask[
-1
].working_plan,
"plan": self.current_subtask[-1].working_plan,
},
),
role="user",
@@ -953,12 +948,11 @@ class DeepResearchAgent(ReActAgent):
async def reflect_failure(self) -> ToolResponse:
"""Reflect on the failure of the action and determine to rephrase
the meta_planner_agent or deeper decompose the current step.
the plan or deeper decompose the current step.
Returns:
ToolResponse:
The reflection about meta_planner_agent
rephrasing and subtask decomposition.
The reflection about plan rephrasing and subtask decomposition.
"""
reflect_sys_prompt = self.prompt_dict["reflect_sys_prompt"]
conversation_history = ""
@@ -974,7 +968,7 @@ class DeepResearchAgent(ReActAgent):
reflect_inst = self.prompt_dict["reflect_instruction"].format_map(
{
"conversation_history": conversation_history,
"meta_planner_agent": self.current_subtask[-1].working_plan,
"plan": self.current_subtask[-1].working_plan,
},
)
try:

View File

@@ -3,14 +3,14 @@
import asyncio
import os
from deep_research_agent import DeepResearchAgent
from agentscope import logger
from agentscope.formatter import DashScopeChatFormatter
from agentscope.mcp import StdIOStatefulClient
from agentscope.memory import InMemoryMemory
from agentscope.message import Msg
from agentscope.model import DashScopeChatModel
from deep_research_agent import DeepResearchAgent
from agentscope.message import Msg
from agentscope.mcp import StdIOStatefulClient
async def main(user_query: str) -> None:

View File

@@ -8,6 +8,7 @@ from pydantic import BaseModel
from agentscope.tool import Toolkit, ToolResponse
TOOL_RESULTS_MAX_WORDS = 5000
@@ -219,7 +220,7 @@ def load_prompt_dict() -> dict:
prompt_dict["reasoning_prompt"] = (
"## Current Subtask:\n{objective}\n"
"## Working Plan:\n{meta_planner_agent}\n"
"## Working Plan:\n{plan}\n"
"{knowledge_gap}\n"
"## Research Depth:\n{depth}"
)
@@ -281,17 +282,14 @@ def load_prompt_dict() -> dict:
prompt_dict["summarize_hint"] = (
"Based on your work history above, examine which step in the "
"following working meta_planner_agent has been "
"completed. Mark the completed "
"following working plan has been completed. Mark the completed "
"step with [DONE] at the end of its line (e.g., k. step k [DONE]) "
"and leave the uncompleted steps unchanged. You MUST return only "
"the updated meta_planner_agent, preserving exactly "
"the same format as the "
"original meta_planner_agent. Do not include any "
"explanations, reasoning, "
"the updated plan, preserving exactly the same format as the "
"original plan. Do not include any explanations, reasoning, "
"or section headers such as '## Working Plan:', just output the"
"updated meta_planner_agent itself."
"\n\n## Working Plan:\n{meta_planner_agent}"
"updated plan itself."
"\n\n## Working Plan:\n{plan}"
)
prompt_dict["summarize_inst"] = (
@@ -307,19 +305,17 @@ def load_prompt_dict() -> dict:
"following report that consolidates and summarizes the essential "
"findings:\n {intermediate_report}\n\n"
"Such report has been saved to the {report_path}. "
"I will now **proceed to the next item** "
"in the working meta_planner_agent."
"I will now **proceed to the next item** in the working plan."
)
prompt_dict["save_report_hint"] = (
"The milestone results of the current "
"item in working meta_planner_agent "
"The milestone results of the current item in working plan "
"are summarized into the following report:\n{intermediate_report}"
)
prompt_dict["reflect_instruction"] = (
"## Work History:\n{conversation_history}\n"
"## Working Plan:\n{meta_planner_agent}\n"
"## Working Plan:\n{plan}\n"
)
prompt_dict["subtask_complete_hint"] = (