{"record":{"id":"ffa68ae0c8cd54bd","repo":"microsoft/semantic-kernel","slug":"failed-to-get-a-response-from-the-agent-please-co","errorCode":null,"errorMessage":"Failed to get a response from the agent. Please consider increasing the auto invoke attempts.","messagePattern":"Failed to get a response from the agent\\. Please consider increasing the auto invoke attempts\\.","errorType":"exception","errorClass":"AgentInvokeException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/bedrock/bedrock_agent.py","lineNumber":355,"sourceCode":"                        file_items = self._handle_files_event(event)\n                    elif BedrockAgentEventType.TRACE in event:\n                        trace_metadata = self._handle_trace_event(event)\n\n                if not chat_message_content or not chat_message_content.content:\n                    raise AgentInvokeException(\"Chat message content is expected but not found in the response.\")\n\n                if file_items:\n                    chat_message_content.items.extend(file_items)\n                if trace_metadata:\n                    chat_message_content.metadata.update({\"trace\": trace_metadata})\n\n                if not chat_message_content:\n                    raise AgentInvokeException(\"No response from the agent.\")\n\n                chat_message_content.metadata[\"thread_id\"] = thread.id\n                return AgentResponseItem(message=chat_message_content, thread=thread)\n\n        raise AgentInvokeException(\n            \"Failed to get a response from the agent. Please consider increasing the auto invoke attempts.\"\n        )\n\n    @trace_agent_invocation\n    @override\n    async def invoke(\n        self,\n        messages: str | ChatMessageContent | list[str | ChatMessageContent] | None = None,\n        *,\n        thread: AgentThread | None = None,\n        on_new_message: Callable[[ChatMessageContent], Awaitable[None]] | None = None,\n        agent_alias: str | None = None,\n        arguments: KernelArguments | None = None,\n        kernel: \"Kernel | None\" = None,\n        **kwargs,\n    ) -> AsyncIterable[AgentResponseItem[ChatMessageContent]]:\n        \"\"\"Invoke an agent.\n","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/bedrock/bedrock_agent.py#L337-L373","documentation":"Raised by get_response after the loop over maximum_auto_invoke_attempts exits without producing a final non-RETURN_CONTROL response. Each iteration where the agent requests function calls (RETURN_CONTROL events) consumes one attempt; if the agent keeps requesting functions on every turn without ever emitting a final chunk, all attempts are exhausted.","triggerScenarios":"Triggered when every iteration of range(self.function_choice_behavior.maximum_auto_invoke_attempts) hits the RETURN_CONTROL branch — the agent repeatedly asks for function calls and never produces a terminal text response.","commonSituations":"A plugin function returns results that always prompt the agent to call another function (circular tool use); maximum_auto_invoke_attempts is too low (default); the agent's instructions overly favor tool use over answering; a function throws and the agent retries indefinitely; the model is stuck in a function-calling loop.","solutions":["Increase maximum_auto_invoke_attempts in FunctionChoiceBehavior.Auto(maximum_auto_invoke_attempts=N) to allow more tool-use rounds.","Review the agent's instructions to ensure it knows when to stop calling functions and produce a final answer.","Check that plugin functions return well-formed results that satisfy the agent's information need (avoid errors that cause retries).","Add a stop condition or restructure the workflow so the agent converges on a text response."],"exampleFix":"// before\nagent = BedrockAgent(model, function_choice_behavior=FunctionChoiceBehavior.Auto())\n# default attempts exhausted\n\n// after\nagent = BedrockAgent(\n    model,\n    function_choice_behavior=FunctionChoiceBehavior.Auto(maximum_auto_invoke_attempts=10),\n)","handlingStrategy":"retry","validationCode":"from semantic_kernel.connectors.ai.function_choice_behavior import FunctionChoiceBehavior\n\nfcb = FunctionChoiceBehavior.Auto(maximum_auto_invoke_attempts=10)  # raise the ceiling\nagent = BedrockAgent(model, function_choice_behavior=fcb)","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentInvokeException\n\nfor attempts in [5, 10, 15]:\n    agent.function_choice_behavior.maximum_auto_invoke_attempts = attempts\n    try:\n        resp = await agent.get_response(message=msg, thread=thread)\n        break\n    except AgentInvokeException as e:\n        if \"increasing the auto invoke attempts\" not in str(e):\n            raise\nelse:\n    raise RuntimeError(\"Agent never converged on a final response\")","preventionTips":["Set maximum_auto_invoke_attempts high enough for your tool-use depth.","Write agent instructions that direct it to produce a final answer after gathering information.","Ensure plugin functions return successful, complete results to avoid retry loops.","Log each RETURN_CONTROL round to detect circular tool use early."],"tags":["bedrock","function-calling","auto-invoke","loop","get-response"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}