# tests/integration/scenarios_declarative/test_data/image_tools/describe_image/test_describe_image_malformed_api_response.yaml
test_case_id: "describe_image_malformed_api_response"
description: "Tests robustness when the vision API returns a 200 OK but with a malformed choice object."
tags: ["all", "agent", "tools", "image_tools"]
skip_intermediate_events: true

setup_artifacts:
  - filename: "test_image.png"
    mime_type: "image/png"
    content_base64: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/wcAAwAB/epv2AAAAABJRU5ErkJggg=="

gateway_input:
  user_prompt: "Describe test_image.png for me."
  user_identity: "test_user@example.com"
  target_agent_name: "TestAgent"
  tool_names: ["describe_image"]

llm_interactions:
  # First LLM call: Agent decides to use the describe_image tool
  - static_response:
      choices:
        - message:
            role: "assistant"
            tool_calls:
              - id: "call_describe_image_malformed_1"
                type: "function"
                function:
                  name: "describe_image"
                  arguments: '{"input_image": "test_image.png"}'
    expected_request:
      tools_present: ["describe_image"]

  # Second LLM call (to the vision API): Primed with a malformed response (message is empty)
  - static_response:
      choices:
        - message:
            role: "assistant"
            # This message is malformed because it has no 'content' or 'tool_calls'
            content:
          finish_reason: "stop"

  # Third LLM call: Agent processes the tool's error output
  - static_response:
      choices:
        - message:
            role: "assistant"
            content: "I encountered an issue describing the image. The API response was invalid."
    expected_request:
      expected_tool_responses_in_llm_messages:
        - tool_call_id_matches_prior_request_index: 0
          response_json_matches:
            status: "error"
            message: "API response does not contain valid message content."

expected_gateway_output:
  - type: "final_response"
    kind: task
    id: '*'
    contextId: session_describe_image_malformed_api_response
    status:
      state: "completed"
      message:
        kind: message
        messageId: '*'
        role: agent
        parts:
          - type: "text"
            text_contains:
              - "The API response was invalid."
