Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
feat: add AgentMaxIterationError exc (#30423)
wangxiaolei9b6b2f31950c
diff --git a/api/core/agent/cot_agent_runner.py b/api/core/agent/cot_agent_runner.pyindex b32e35d0cac..a55f2d0f5fa 100644--- a/api/core/agent/cot_agent_runner.py+++ b/api/core/agent/cot_agent_runner.py@@ -22,6 +22,7 @@ from core.prompt.agent_history_prompt_transform import AgentHistoryPromptTransfofrom core.tools.__base.tool import Toolfrom core.tools.entities.tool_entities import ToolInvokeMetafrom core.tools.tool_engine import ToolEngine+from core.workflow.nodes.agent.exc import AgentMaxIterationErrorfrom models.model import Messagelogger = logging.getLogger(__name__)@@ -165,6 +166,11 @@ class CotAgentRunner(BaseAgentRunner, ABC):scratchpad.thought = scratchpad.thought.strip() or "I am thinking about how to help you"self._agent_scratchpad.append(scratchpad)+ # Check if max iteration is reached and model still wants to call tools+ if iteration_step == max_iteration_steps and scratchpad.action:+ if scratchpad.action.action_name.lower() != "final answer":+ raise AgentMaxIterationError(app_config.agent.max_iteration)+# get llm usageif "usage" in usage_dict:if usage_dict["usage"] is not None:diff --git a/api/core/agent/fc_agent_runner.py b/api/core/agent/fc_agent_runner.pyindex dcc1326b33b..68d14ad0272 100644--- a/api/core/agent/fc_agent_runner.py+++ b/api/core/agent/fc_agent_runner.py@@ -25,6 +25,7 @@ from core.model_runtime.entities.message_entities import ImagePromptMessageContefrom core.prompt.agent_history_prompt_transform import AgentHistoryPromptTransformfrom core.tools.entities.tool_entities import ToolInvokeMetafrom core.tools.tool_engine import ToolEngine+from core.workflow.nodes.agent.exc import AgentMaxIterationErrorfrom models.model import Messagelogger = logging.getLogger(__name__)@@ -222,6 +223,10 @@ class FunctionCallAgentRunner(BaseAgentRunner):final_answer += response + "\n"+ # Check if max iteration is reached and model still wants to call tools+ if iteration_step == max_iteration_steps and tool_calls:+ raise AgentMaxIterationError(app_config.agent.max_iteration)+# call toolstool_responses = []for tool_call_id, tool_call_name, tool_call_args in tool_calls:diff --git a/api/core/workflow/nodes/agent/exc.py b/api/core/workflow/nodes/agent/exc.pyindex 944f5f0b206..ba2c83d8a61 100644--- a/api/core/workflow/nodes/agent/exc.py+++ b/api/core/workflow/nodes/agent/exc.py@@ -119,3 +119,14 @@ class AgentVariableTypeError(AgentNodeError):self.expected_type = expected_typeself.actual_type = actual_typesuper().__init__(message)+++class AgentMaxIterationError(AgentNodeError):+ """Exception raised when the agent exceeds the maximum iteration limit."""++ def __init__(self, max_iteration: int):+ self.max_iteration = max_iteration+ super().__init__(+ f"Agent exceeded the maximum iteration limit of {max_iteration}. "+ f"The agent was unable to complete the task within the allowed number of iterations."+ )