- 
                Notifications
    
You must be signed in to change notification settings  - Fork 639
 
Description
Expected Behaviour
When orchestrator.route_request() returns an AgentResponse, the response.output.content should contain at least one item with a 'text' key that can be accessed via response.output.content[0]['text'].
Current Behaviour
In some cases, response.output.content returns an empty list [], causing an IndexError: list index out of range when trying to access response.output.content[0]['text']. This happens intermittently but repeatedly for certain agent configurations.
The bug appears to be related to the ConversationMessage object structure where the content field should be a list of dictionaries with 'text' keys, but sometimes returns as an empty list despite successful agent processing. This suggests an issue in how the framework constructs the response object after agent execution completes.
LOGS:
** AGENT PROCESSING FLOW **
==>>>>> Supervisor sending Task Followup Specialist: Liste todas as tarefas ativas
[INFO] [Follow-Up - Tool:list_tasks] Retrieved 10 tasks from local ...[truncated]
<<<<<===Supervisor received from Task Followup Specialist:
Tasks found: 10 tarefas organizadas por categoria:
- Compra de bandeja de morango no Oba (Aguardando informações - Data de entrega, marca preferida e dia da semana)
- Impressão de pô...[truncated]
** EXECUTION TIMES **
> Classifying user intent: 2.3545236587524414s
> Agent Task Followup Leader| Processing request: 24.730260372161865s
** FRAMEWORK RESPONSE **
Response from orchestrator: AgentResponse(
    metadata=AgentProcessingResult(
        user_input='xxx xxxx xxxx', 
        agent_id=xxxxx-xxx-xx', 
        agent_name='XXX XXX', 
        user_id='xxx', 
        session_id='xxx', 
        additional_params={}
    ), 
    output=<agent_squad.types.types.ConversationMessage object at 0x7f97d0177e00>, 
    streaming=False
)
** ERROR OCCURS **
[ERROR] No agent error: list index out of range
Traceback (most recent call last):
  File "/var/task/main.py", line 557, in ask_orchestrator
    answer = response.output.content[0]['text']
    ~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
Code snippet
try:
    response = await orchestrator.route_request(
        message_input,
        account_id,
        session_id
    )
except Exception as e:
    logger.error(f"Error during routing request: {str(e)}")
    return None
logger.info(f"Response from orchestrator: {response}")
try:
    answer = response.output.content[0]['text']  # ← IndexError occurs here
    logger.info(f"Orchestrator Answer: {answer}")
    agent_id = response.metadata.agent_id
    agent_name = response.metadata.agent_name
    user_input = response.metadata.user_input
    
except Exception as e:
    # Fallback handling
    answer = response.output if isinstance(response.output, str) else "Default message"
    agent_id = "no_agent_selected"
    agent_name = "No Agent"
    user_input = message_inputPossible Solution
No response
Steps to Reproduce
- Set up a hierarchical multi-agent system with supervisor agents coordinating specialist agents
 - Configure agents with tool execution and long processing times (20+ seconds)
 - Send requests that trigger supervisor → specialist agent routing
 - The bug occurs intermittently when the specialist agent completes processing but the ConversationMessage.content list is empty