fix(typing): resolve mypy static type checking errors

pull/21945/head
baonudesifeizhai 11 months ago
parent 1d545fc85d
commit b1f3b16c70

@ -103,7 +103,7 @@ class AgentNode(ToolNode):
try: try:
# convert tool messages # convert tool messages
agent_thoughts = [] agent_thoughts: list = []
from core.tools.entities.tool_entities import ToolInvokeMessage from core.tools.entities.tool_entities import ToolInvokeMessage
@ -130,10 +130,10 @@ class AgentNode(ToolNode):
from core.tools.entities.tool_entities import ToolInvokeMessage from core.tools.entities.tool_entities import ToolInvokeMessage
def enhanced_message_stream(): def enhanced_message_stream():
yield thought_log_message yield thought_log_message
yield from message_stream yield from message_stream
yield from self._transform_message( yield from self._transform_message(
message_stream, message_stream,
{ {
@ -141,7 +141,7 @@ class AgentNode(ToolNode):
"agent_strategy": cast(AgentNodeData, self.node_data).agent_strategy_name, "agent_strategy": cast(AgentNodeData, self.node_data).agent_strategy_name,
}, },
parameters_for_log, parameters_for_log,
agent_thoughts agent_thoughts,
) )
except PluginDaemonClientSideError as e: except PluginDaemonClientSideError as e:
yield RunCompletedEvent( yield RunCompletedEvent(

@ -370,21 +370,16 @@ class ToolNode(BaseNode[ToolNodeData]):
yield agent_log yield agent_log
# Add agent_logs to outputs['json'] to ensure frontend can access thinking process # Add agent_logs to outputs['json'] to ensure frontend can access thinking process
json_output = json.copy() json_output: dict[str, Any] = {}
if agent_logs: if json:
if not json_output: if isinstance(json, list) and len(json) == 1:
json_output = {}
elif isinstance(json_output, list) and len(json_output) == 1:
# If json is a list with only one element, convert it to a dictionary # If json is a list with only one element, convert it to a dictionary
json_output = json_output[0] if isinstance(json_output[0], dict) else {"data": json_output[0]} json_output = json[0] if isinstance(json[0], dict) else {"data": json[0]}
elif isinstance(json_output, list): elif isinstance(json, list):
# If json is a list with multiple elements, create a dictionary containing all data # If json is a list with multiple elements, create a dictionary containing all data
json_output = {"data": json_output} json_output = {"data": json}
# Ensure json_output is a dictionary type
if not isinstance(json_output, dict):
json_output = {"data": json_output}
if agent_logs:
# Add agent_logs to json output # Add agent_logs to json output
json_output["agent_logs"] = [ json_output["agent_logs"] = [
{ {
@ -402,8 +397,7 @@ class ToolNode(BaseNode[ToolNodeData]):
yield RunCompletedEvent( yield RunCompletedEvent(
run_result=NodeRunResult( run_result=NodeRunResult(
status=WorkflowNodeExecutionStatus.SUCCEEDED, status=WorkflowNodeExecutionStatus.SUCCEEDED,
outputs={"text": text, "files": ArrayFileSegment(value=files), outputs={"text": text, "files": ArrayFileSegment(value=files), "json": json_output, **variables},
"json": json_output, **variables},
metadata={ metadata={
**agent_execution_metadata, **agent_execution_metadata,
WorkflowNodeExecutionMetadataKey.TOOL_INFO: tool_info, WorkflowNodeExecutionMetadataKey.TOOL_INFO: tool_info,

Loading…
Cancel
Save