microsoft/semantic-kernel · error · AgentInvokeException
Failed to get a response from the agent. Please consider inc
Error message
Failed to get a response from the agent. Please consider increasing the auto invoke attempts.
What it means
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.
Source
Thrown at python/semantic_kernel/agents/bedrock/bedrock_agent.py:355
file_items = self._handle_files_event(event)
elif BedrockAgentEventType.TRACE in event:
trace_metadata = self._handle_trace_event(event)
if not chat_message_content or not chat_message_content.content:
raise AgentInvokeException("Chat message content is expected but not found in the response.")
if file_items:
chat_message_content.items.extend(file_items)
if trace_metadata:
chat_message_content.metadata.update({"trace": trace_metadata})
if not chat_message_content:
raise AgentInvokeException("No response from the agent.")
chat_message_content.metadata["thread_id"] = thread.id
return AgentResponseItem(message=chat_message_content, thread=thread)
raise AgentInvokeException(
"Failed to get a response from the agent. Please consider increasing the auto invoke attempts."
)
@trace_agent_invocation
@override
async def invoke(
self,
messages: str | ChatMessageContent | list[str | ChatMessageContent] | None = None,
*,
thread: AgentThread | None = None,
on_new_message: Callable[[ChatMessageContent], Awaitable[None]] | None = None,
agent_alias: str | None = None,
arguments: KernelArguments | None = None,
kernel: "Kernel | None" = None,
**kwargs,
) -> AsyncIterable[AgentResponseItem[ChatMessageContent]]:
"""Invoke an agent.
View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before
agent = BedrockAgent(model, function_choice_behavior=FunctionChoiceBehavior.Auto())
# default attempts exhausted
// after
agent = BedrockAgent(
model,
function_choice_behavior=FunctionChoiceBehavior.Auto(maximum_auto_invoke_attempts=10),
) Defensive patterns
Strategy: retry
Validate before calling
from semantic_kernel.connectors.ai.function_choice_behavior import FunctionChoiceBehavior fcb = FunctionChoiceBehavior.Auto(maximum_auto_invoke_attempts=10) # raise the ceiling agent = BedrockAgent(model, function_choice_behavior=fcb)
Try / catch
from semantic_kernel.exceptions.agent_exceptions import AgentInvokeException
for attempts in [5, 10, 15]:
agent.function_choice_behavior.maximum_auto_invoke_attempts = attempts
try:
resp = await agent.get_response(message=msg, thread=thread)
break
except AgentInvokeException as e:
if "increasing the auto invoke attempts" not in str(e):
raise
else:
raise RuntimeError("Agent never converged on a final response") Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No function results were returned.
- Type {type_} is not allowed in bedrock function parameter ty
- Messages must be a string or a ChatMessageContent for Bedroc
- Chat message content is expected but not found in the respon
- No response from the agent.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/ffa68ae0c8cd54bd.
Report an issue: GitHub.