Skip to content

Build and run agents you can see, understand and trust.

fix(plan): fix the bug in plan notebook and support to convert string index into `int` automatically (#858)

DavdGao995440040359
diff --git a/src/agentscope/_version.py b/src/agentscope/_version.py
index 5cbcc5dd4..9fddc7881 100644
--- a/src/agentscope/_version.py
+++ b/src/agentscope/_version.py
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
"""The version of agentscope."""
-__version__ = "1.0.6dev"
+__version__ = "1.0.6"
diff --git a/src/agentscope/plan/_plan_notebook.py b/src/agentscope/plan/_plan_notebook.py
index efbef1832..ff12f9365 100644
--- a/src/agentscope/plan/_plan_notebook.py
+++ b/src/agentscope/plan/_plan_notebook.py
@@ -324,43 +324,64 @@ class PlanNotebook(StateModule):
`ToolResponse`:
The response of the tool call.
"""
+ # Validate the arguments first
+ response: list[str] = []
+ if isinstance(subtask_idx, str):
+ try:
+ subtask_idx = int(subtask_idx)
+ except ValueError:
+ pass
+
+ if not isinstance(subtask_idx, int):
+ response.append(
+ f"Invalid type for argument 'subtask_idx'. "
+ f"Expected 'int', but got '{type(subtask_idx)}'.",
+ )
+
if action not in ["add", "revise", "delete"]:
- return ToolResponse(
- content=[
- TextBlock(
- type="text",
- text=f"Invalid action '{action}'. Must be one of "
- "'add', 'revise', 'delete'.",
- ),
- ],
+ response.append(
+ f"Invalid action '{action}'. Must be one of 'add', 'revise', "
+ f"'delete'.",
)
if action in ["add", "revise"] and subtask is None:
- return ToolResponse(
- content=[
- TextBlock(
- type="text",
- text=f"The subtask must be provided when action is "
- f"'{action}', but got None.",
- ),
- ],
+ response.append(
+ f"The subtask must be provided when action is '{action}', "
+ "but got None.",
)
self._validate_current_plan()
# validate subtask_idx
- if subtask_idx >= len(self.current_plan.subtasks):
+ if action != "add" and subtask_idx >= len(self.current_plan.subtasks):
+ response.append(
+ f"Invalid subtask_idx '{subtask_idx}' for action '{action}'. "
+ f"Must be between 0 "
+ f"and {len(self.current_plan.subtasks) - 1}.",
+ )
+
+ if action == "add" and not (
+ 0 <= subtask_idx <= len(self.current_plan.subtasks)
+ ):
+ response.append(
+ f"Invalid subtask_idx '{subtask_idx}' for action 'add'. "
+ f"Must be between 0 and {len(self.current_plan.subtasks)}.",
+ )
+
+ if response:
return ToolResponse(
content=[
TextBlock(
type="text",
- text=f"Invalid subtask_idx '{subtask_idx}'. Must "
- f"be between 0 and "
- f"{len(self.current_plan.subtasks) - 1}.",
+ text="Error: " + response[0],
),
],
)
+ if subtask is not None:
+ # Convert to SubTask model if it's a dict
+ subtask = SubTask.model_validate(subtask)
+
if action == "delete":
subtask = self.current_plan.subtasks.pop(subtask_idx)
await self._trigger_plan_change_hooks()
@@ -387,6 +408,7 @@ class PlanNotebook(StateModule):
],
)
+ # revise
self.current_plan.subtasks[subtask_idx] = subtask
await self._trigger_plan_change_hooks()
return ToolResponse(
@@ -418,6 +440,23 @@ class PlanNotebook(StateModule):
"""
self._validate_current_plan()
+ if isinstance(subtask_idx, str):
+ try:
+ subtask_idx = int(subtask_idx)
+ except ValueError:
+ pass
+
+ if not isinstance(subtask_idx, int):
+ return ToolResponse(
+ content=[
+ TextBlock(
+ type="text",
+ text=f"Invalid type for argument 'subtask_idx'. "
+ f"Expected 'int', but got '{type(subtask_idx)}'.",
+ ),
+ ],
+ )
+
if not 0 <= subtask_idx < len(self.current_plan.subtasks):
return ToolResponse(
content=[
@@ -514,6 +553,23 @@ class PlanNotebook(StateModule):
"""
self._validate_current_plan()
+ if isinstance(subtask_idx, str):
+ try:
+ subtask_idx = int(subtask_idx)
+ except ValueError:
+ pass
+
+ if not isinstance(subtask_idx, int):
+ return ToolResponse(
+ content=[
+ TextBlock(
+ type="text",
+ text=f"Invalid type for argument 'subtask_idx'. "
+ f"Expected 'int', but got '{type(subtask_idx)}'.",
+ ),
+ ],
+ )
+
if not 0 <= subtask_idx < len(self.current_plan.subtasks):
return ToolResponse(
content=[