Skip to content

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

fix(tool): preserve error state in tool responses (#2178)

KXH7be0da001fc4
diff --git a/src/agentscope/tool/_response.py b/src/agentscope/tool/_response.py
index db6eed57a..999e284e7 100644
--- a/src/agentscope/tool/_response.py
+++ b/src/agentscope/tool/_response.py
@@ -135,9 +135,15 @@ class ToolResponse(BaseModel):
# worse.
if chunk.state == ToolResultState.ERROR:
self.state = ToolResultState.ERROR
- elif chunk.state == "interrupted":
+ elif (
+ self.state != ToolResultState.ERROR
+ and chunk.state == ToolResultState.INTERRUPTED
+ ):
self.state = ToolResultState.INTERRUPTED
- elif chunk.state == ToolResultState.DENIED:
+ elif (
+ self.state != ToolResultState.ERROR
+ and chunk.state == ToolResultState.DENIED
+ ):
self.state = ToolResultState.DENIED
self.metadata.update(chunk.metadata)